Module: OracleEnhancedAdapterPlusXmltype::InstanceMethods

Defined in:
lib/oracle_enhanced_plus_xmltype/oracle_enhanced_adapter_with_xmltype.rb

Instance Method Summary collapse

Instance Method Details

#quote(value, column = nil) ⇒ Object

:nodoc:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/oracle_enhanced_plus_xmltype/oracle_enhanced_adapter_with_xmltype.rb', line 21

def quote(value, column = nil) #:nodoc:
  if value && column
    case column.type
    when :xmltype
      quote_xml(value)
    when :text, :binary
      %Q{empty_#{ column.sql_type.downcase rescue 'blob' }()}
    # NLS_DATE_FORMAT independent TIMESTAMP support
    when :timestamp
      quote_timestamp_with_to_timestamp(value)
    # NLS_DATE_FORMAT independent DATE support
    when :date, :time, :datetime
      quote_date_with_to_date(value)
    when :raw
      quote_raw(value)
    when :string
      # NCHAR and NVARCHAR2 literals should be quoted with N'...'.
      # Read directly instance variable as otherwise migrations with table column default values are failing
      # as migrations pass ColumnDefinition object to this method.
      # Check if instance variable is defined to avoid warnings about accessing undefined instance variable.
      column.instance_variable_defined?('@nchar') && column.instance_variable_get('@nchar') ? 'N' << super : super
    else
      super
    end
  elsif value.acts_like?(:date)
    quote_date_with_to_date(value)
  elsif value.acts_like?(:time)
    value.to_i == value.to_f ? quote_date_with_to_date(value) : quote_timestamp_with_to_timestamp(value)
  else
    super
  end
end

#quote_xml(value, quoted = true) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/oracle_enhanced_plus_xmltype/oracle_enhanced_adapter_with_xmltype.rb', line 8

def quote_xml(value, quoted = true)
  case value
  when Hash
    quoted ? "'#{value.to_xml}'" : value.to_xml
  when nil
    nil
  else
    raise ArgumentError, "XMLTYPE column must be of type Hash"
  end
  
end

#type_cast(value, column) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/oracle_enhanced_plus_xmltype/oracle_enhanced_adapter_with_xmltype.rb', line 54

def type_cast(value, column)
  case value
  when true, false
    if emulate_booleans_from_strings || column && column.type == :string
      self.class.boolean_to_string(value)
    else
      value ? 1 : 0
    end
  when Date, Time
    if value.acts_like?(:time)
      zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
      value.respond_to?(zone_conversion_method) ? value.send(zone_conversion_method) : value
    else
      value
    end
  else
    if column.type == :xmltype
      quote_xml(value, false)
    else
      super
    end
  end
end