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 04:59:33 -0500 |
commit | a712e08ebe21f6d8653a0e6602df2e0f5d40d9ca (patch) | |
tree | 7cde9049f55e039627b3cb6bfcc45e58bcadd4a8 /activerecord/lib/active_record/connection_adapters/abstract/quoting.rb | |
parent | 1b75666f7f4ec7f013182d24b919ca27b0ca0068 (diff) | |
download | rails-a712e08ebe21f6d8653a0e6602df2e0f5d40d9ca.tar.gz rails-a712e08ebe21f6d8653a0e6602df2e0f5d40d9ca.tar.bz2 rails-a712e08ebe21f6d8653a0e6602df2e0f5d40d9ca.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 d18b9c991f..aec4654eee 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, ActiveSupport::Duration 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)}'" when Class then "'#{value.to_s}'" |