diff options
author | Dylan Smith <Dylan.Smith@shopify.com> | 2013-02-06 13:19:09 -0500 |
---|---|---|
committer | Dylan Smith <Dylan.Smith@shopify.com> | 2013-02-07 05:02:38 -0500 |
commit | 04c2d2e2e4197a1564c33f09d3e52253d845925f (patch) | |
tree | c57b23a3197d773dcce73a322806f49833208dbf /activerecord/lib/active_record/connection_adapters/abstract/quoting.rb | |
parent | b4f189a162f4280b360dbc2a6635bbff6c6f09bc (diff) | |
download | rails-04c2d2e2e4197a1564c33f09d3e52253d845925f.tar.gz rails-04c2d2e2e4197a1564c33f09d3e52253d845925f.tar.bz2 rails-04c2d2e2e4197a1564c33f09d3e52253d845925f.zip |
active_record: Quote numeric values compared to string columns.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/quoting.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/quoting.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb index f93c7cd74a..fe0b1959f6 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb @@ -25,13 +25,19 @@ module ActiveRecord when true, false if column && column.type == :integer value ? '1' : '0' + elsif column && [:text, :string, :binary].include?(column.type) + value ? "'1'" : "'0'" else value ? quoted_true : quoted_false end # BigDecimals need to be put in a non-normalized form and quoted. when nil then "NULL" - when BigDecimal then value.to_s('F') - when Numeric then value.to_s + when Numeric, ActiveSupport::Duration + value = BigDecimal === value ? value.to_s('F') : value.to_s + if column && ![:integer, :float, :decimal].include?(column.type) + value = "'#{value}'" + end + value when Date, Time then "'#{quoted_date(value)}'" when Symbol then "'#{quote_string(value.to_s)}'" else |