Browse files

bigdecimal should be typecast to a float on sqlite3. fixes #2162

  • Loading branch information...
1 parent ff05736 commit 56fb7fc1b217297c412d7d75e8a2fd85b3bd1a15 @tenderlove tenderlove committed Jul 20, 2011
View
5 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -155,6 +155,11 @@ def quoted_date(value) #:nodoc:
end
end
+ def type_cast(value, column) # :nodoc:
+ return super unless BigDecimal === value
+
+ value.to_f
+ end
# DATABASE STATEMENTS ======================================
View
2 activerecord/test/cases/adapters/sqlite3/quoting_test.rb
@@ -67,7 +67,7 @@ def test_type_cast_string
def test_type_cast_bigdecimal
bd = BigDecimal.new '10.0'
- assert_equal bd.to_s('F'), @conn.type_cast(bd, nil)
+ assert_equal bd.to_f, @conn.type_cast(bd, nil)
end
def test_type_cast_unknown
View
11 activerecord/test/cases/base_test.rb
@@ -1110,6 +1110,17 @@ class NumericData < ActiveRecord::Base
self.table_name = 'numeric_data'
end
+ def test_big_decimal_conditions
+ m = NumericData.new(
+ :bank_balance => 1586.43,
+ :big_bank_balance => BigDecimal("1000234000567.95"),
+ :world_population => 6000000000,
+ :my_house_population => 3
+ )
+ assert m.save
+ assert_equal 0, NumericData.where("bank_balance > ?", 2000.0).count
+ end
+
def test_numeric_fields
m = NumericData.new(
:bank_balance => 1586.43,

0 comments on commit 56fb7fc

Please sign in to comment.