diff options
author | Łukasz Strzałkowski <lukasz.strzalkowski@gmail.com> | 2013-03-12 16:05:01 +0100 |
---|---|---|
committer | Łukasz Strzałkowski <lukasz.strzalkowski@gmail.com> | 2013-03-12 16:13:01 +0100 |
commit | aae89ee8607a802557b4877feb995204e0b58fed (patch) | |
tree | dad783f33dc8510d26c13328c5015c41b608af14 | |
parent | d25a82280f977664e3b3d49c13bb68502718f6e2 (diff) | |
download | rails-aae89ee8607a802557b4877feb995204e0b58fed.tar.gz rails-aae89ee8607a802557b4877feb995204e0b58fed.tar.bz2 rails-aae89ee8607a802557b4877feb995204e0b58fed.zip |
Cast number to string in Postgres
fixes #9170
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb | 9 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/quoting_test.rb | 8 |
2 files changed, 14 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb index 47e2e3928f..43f991b362 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb @@ -51,9 +51,12 @@ module ActiveRecord super end when Numeric - return super unless column.sql_type == 'money' - # Not truly string input, so doesn't require (or allow) escape string syntax. - "'#{value}'" + if column.sql_type == 'money' || [:string, :text].include?(column.type) + # Not truly string input, so doesn't require (or allow) escape string syntax. + "'#{value}'" + else + super + end when String case column.sql_type when 'bytea' then "'#{escape_bytea(value)}'" diff --git a/activerecord/test/cases/adapters/postgresql/quoting_test.rb b/activerecord/test/cases/adapters/postgresql/quoting_test.rb index 685f0ea74f..b3429648ee 100644 --- a/activerecord/test/cases/adapters/postgresql/quoting_test.rb +++ b/activerecord/test/cases/adapters/postgresql/quoting_test.rb @@ -44,6 +44,14 @@ module ActiveRecord c = Column.new(nil, 1, 'float') assert_equal "'Infinity'", @conn.quote(infinity, c) end + + def test_quote_cast_numeric + fixnum = 666 + c = Column.new(nil, nil, 'string') + assert_equal "'666'", @conn.quote(fixnum, c) + c = Column.new(nil, nil, 'text') + assert_equal "'666'", @conn.quote(fixnum, c) + end end end end |