Created
January 24, 2012 02:21
-
-
Save alexgb/1667390 to your computer and use it in GitHub Desktop.
Monkey patch for activerecord-jdbc-adapter to allow querying Oracle views
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'arjdbc/oracle/adapter' | |
module ArJdbc | |
module Oracle | |
# fix so that we can read column names for Oracle views | |
def ora_columns(table_name, name=nil) | |
jdbc_columns(table_name).map do |column| | |
column.extend(::ArJdbc::Oracle::Column) | |
end | |
end | |
module Column | |
# fix apparently broken string to time conversion | |
def self.string_to_time(value, klass) | |
ActiveRecord::ConnectionAdapters::Column.string_to_time(value) | |
end | |
# typecast BigDecimal columns with no precision to integers | |
alias :old_type_cast :type_cast | |
def type_cast(value) | |
return nil if value.nil? | |
puts "typecasting #{value}" | |
if type == :decimal && precision.nil? | |
value.to_i | |
else | |
old_type_cast(value) | |
end | |
end | |
# typecast BigDecimal columns with no precision to integers | |
alias :old_type_cast_code :type_cast_code | |
def type_cast_code(var_name) | |
if type == :decimal && precision.nil? | |
"#{var_name}.to_i" | |
else | |
old_type_cast_code(var_name) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment