From fbdd58081e3d8a14bef68c824848571c873af21b Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Mon, 26 May 2014 07:01:53 -0700 Subject: Refactor the type casting of booleans in MySQL --- .../connection_adapters/abstract/quoting.rb | 12 ++++++++++-- .../connection_adapters/abstract_mysql_adapter.rb | 19 ++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) (limited to 'activerecord/lib/active_record') 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: -- cgit v1.2.3