Module: OracleEnhancedOCIConnectionWithXmltype::InstanceMethods

Defined in:
lib/oracle_enhanced_plus_xmltype/oracle_enhanced_oci_connection_with_xmltype.rb

Instance Method Summary collapse

Instance Method Details

#typecast_result_value(value, get_lob_value) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
# File 'lib/oracle_enhanced_plus_xmltype/oracle_enhanced_oci_connection_with_xmltype.rb', line 7

def typecast_result_value(value, get_lob_value)
  case value
  when Fixnum, Bignum
    value
  when String
    if value.match(/\<\?xml/i)
      Hash.from_xml(value)["hash"]
    else
      value
    end
  when Float, BigDecimal
    # return Fixnum or Bignum if value is integer (to avoid issues with _before_type_cast values for id attributes)
    value == (v_to_i = value.to_i) ? v_to_i : value
  when OraNumber
    # change OraNumber value (returned in early versions of ruby-oci8 2.0.x) to BigDecimal
    value == (v_to_i = value.to_i) ? v_to_i : BigDecimal.new(value.to_s)
  when OCI8::LOB
    if get_lob_value
      data = value.read || ""     # if value.read returns nil, then we have an empty_clob() i.e. an empty string
      # In Ruby 1.9.1 always change encoding to ASCII-8BIT for binaries
      data.force_encoding('ASCII-8BIT') if data.respond_to?(:force_encoding) && value.is_a?(OCI8::BLOB)
      data
    else
      value
    end
    # ruby-oci8 1.0 returns OraDate
    # ruby-oci8 2.0 returns Time or DateTime
  when OraDate, Time, DateTime
    if ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates && date_without_time?(value)
      value.to_date
    else
      create_time_with_default_timezone(value)
    end
  when OraDate, Time, DateTime
    if ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates && date_without_time?(value)
      value.to_date
    else
      create_time_with_default_timezone(value)
    end
  else
    value
  end
end