diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-05-26 07:01:53 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-05-26 10:34:02 -0700 |
commit | fbdd58081e3d8a14bef68c824848571c873af21b (patch) | |
tree | c6d758e4e69a53dc83d4cb96a0805d86171f82bf /activerecord/lib | |
parent | 7a5fbaf02ccf41953f88e7e73f3574796b8b29ba (diff) | |
download | rails-fbdd58081e3d8a14bef68c824848571c873af21b.tar.gz rails-fbdd58081e3d8a14bef68c824848571c873af21b.tar.bz2 rails-fbdd58081e3d8a14bef68c824848571c873af21b.zip |
Refactor the type casting of booleans in MySQL
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/quoting.rb | 12 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 19 |
2 files changed, 18 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb index 169c00cb1a..768d2b6d36 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb @@ -55,8 +55,8 @@ module ActiveRecord case value when String, ActiveSupport::Multibyte::Chars value.to_s - when true then 't' - when false then 'f' + when true then unquoted_true + when false then unquoted_false when nil then nil # BigDecimals need to be put in a non-normalized form and quoted. when BigDecimal then value.to_s('F') @@ -101,10 +101,18 @@ module ActiveRecord "'t'" end + def unquoted_true + 't' + end + def quoted_false "'f'" end + def unquoted_false + 'f' + end + def quoted_date(value) if value.acts_like?(:time) zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index d3f8470c30..8efb288c95 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -178,17 +178,6 @@ module ActiveRecord true end - def type_cast(value, column) - case value - when TrueClass - 1 - when FalseClass - 0 - else - super - end - end - # MySQL 4 technically support transaction isolation, but it is affected by a bug # where the transaction level gets persisted for the whole session: # @@ -253,10 +242,18 @@ module ActiveRecord QUOTED_TRUE end + def unquoted_true + 1 + end + def quoted_false QUOTED_FALSE end + def unquoted_false + 0 + end + # REFERENTIAL INTEGRITY ==================================== def disable_referential_integrity #:nodoc: |