Skip to content

Commit dc4611b

Browse files
committed
need to handle boolean conversion for oracle since we get 1.0 decimals
... this is due "corrected" JDBC type to Ruby conversion
1 parent 7e40233 commit dc4611b

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

lib/arjdbc/oracle/adapter.rb

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,17 @@ def jdbc_column_class
4848

4949
module Column
5050

51-
def primary=(val)
51+
def primary=(value)
5252
super
53-
if val && @sql_type =~ /^NUMBER$/i
54-
@type = :integer
55-
end
53+
@type = :integer if value && @sql_type =~ /^NUMBER$/i
5654
end
5755

5856
def type_cast(value)
5957
return nil if value.nil?
6058
case type
6159
when :datetime then ArJdbc::Oracle::Column.string_to_time(value)
6260
when :timestamp then ArJdbc::Oracle::Column.string_to_time(value)
61+
when :boolean then ArJdbc::Oracle::Column.value_to_boolean(value)
6362
else
6463
super
6564
end
@@ -69,11 +68,25 @@ def type_cast_code(var_name)
6968
case type
7069
when :datetime then "ArJdbc::Oracle::Column.string_to_time(#{var_name})"
7170
when :timestamp then "ArJdbc::Oracle::Column.string_to_time(#{var_name})"
71+
when :boolean then "ArJdbc::Oracle::Column.value_to_boolean(#{var_name})"
7272
else
7373
super
7474
end
7575
end
7676

77+
# convert a value to a boolean
78+
def self.value_to_boolean(value)
79+
# NOTE: Oracle JDBC meta-data gets us DECIMAL for NUMBER(1) values
80+
# thus we're likely to get a column back as BigDecimal (e.g. 1.0)
81+
if value.is_a?(String)
82+
value.blank? ? nil : value == '1'
83+
elsif value.is_a?(Numeric)
84+
value.to_i == 1 # <BigDecimal:7b5bfe,'0.1E1',1(4)>
85+
else
86+
!! value
87+
end
88+
end
89+
7790
def self.string_to_time(string)
7891
return string unless string.is_a?(String)
7992
return nil if string.empty?
@@ -490,8 +503,7 @@ def quote_column_name(name) #:nodoc:
490503
end
491504

492505
def quote(value, column = nil) # :nodoc:
493-
# Arel 2 passes SqlLiterals through
494-
return value if sql_literal?(value)
506+
return value if sql_literal?(value) # Arel 2 passes SqlLiterals through
495507

496508
column_type = column && column.type
497509
if column_type == :text || column_type == :binary

0 commit comments

Comments
 (0)