# File lib/arjdbc/oracle/column.rb, line 17 def primary=(value) super @type = :integer if value && @sql_type =~ /^NUMBER$/i end
module ArJdbc::Oracle::Column
Public Class Methods
included(base)
click to toggle source
# File lib/arjdbc/oracle/column.rb, line 12 def self.included(base) # NOTE: assumes a standalone OracleColumn class class << base; include Cast; end # unless AR42 end
Public Instance Methods
primary=(value)
click to toggle source
Calls superclass method
sql_type()
click to toggle source
# File lib/arjdbc/oracle/column.rb, line 43 def sql_type (@sql_type || '').start_with?('XMLTYPE') ? 'XMLTYPE' : @sql_type end
type_cast(value)
click to toggle source
Calls superclass method
# File lib/arjdbc/oracle/column.rb, line 22 def type_cast(value) return nil if value.nil? case type when :datetime then self.class.string_to_time(value) when :timestamp then self.class.string_to_time(value) when :boolean then self.class.value_to_boolean(value) else super end end
type_cast_code(var_name)
click to toggle source
Calls superclass method
# File lib/arjdbc/oracle/column.rb, line 33 def type_cast_code(var_name) case type when :datetime then "#{self.class.name}.string_to_time(#{var_name})" when :timestamp then "#{self.class.name}.string_to_time(#{var_name})" when :boolean then "#{self.class.name}.value_to_boolean(#{var_name})" else super end end
Private Instance Methods
default_value(value)
click to toggle source
Post process default value from JDBC into a Rails-friendly format (columns{-internal})
# File lib/arjdbc/oracle/column.rb, line 77 def default_value(value) return nil unless value value = value.strip # Not sure why we need this for Oracle? upcase = value.upcase return nil if upcase == "NULL" # SYSDATE default should be treated like a NULL value return nil if upcase == "SYSDATE" # jdbc returns column default strings with actual single quotes around the value. return $1 if value =~ /^'(.*)'$/ value end
extract_limit(sql_type)
click to toggle source
Calls superclass method
# File lib/arjdbc/oracle/column.rb, line 49 def extract_limit(sql_type) case sql_type when /^(clob|date)/i then nil when /^xml/i then nil else super end end
simplified_type(field_type)
click to toggle source
Calls superclass method
# File lib/arjdbc/oracle/column.rb, line 57 def simplified_type(field_type) case field_type when /char/i then :string when /float|double/i then :float when /int/i then :integer when /^number\(1\)$/i then Oracle.emulate_booleans? ? :boolean : :integer when /^num|dec|real/i then extract_scale(field_type) == 0 ? :integer : :decimal # Oracle TIMESTAMP stores the date and time to up to 9 digits of sub-second precision when /TIMESTAMP/i then :timestamp # Oracle DATE stores the date and time to the second when /DATE|TIME/i then :datetime when /CLOB/i then :text when /BLOB/i then :binary when /XML/i then :xml else super end end