aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-26 14:39:50 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-26 14:39:50 -0300
commitcfd9d1d3e1e1d6bd51216d2e458337b5e904b7b0 (patch)
treec6d758e4e69a53dc83d4cb96a0805d86171f82bf /activerecord/lib/active_record
parent7a5fbaf02ccf41953f88e7e73f3574796b8b29ba (diff)
parentfbdd58081e3d8a14bef68c824848571c873af21b (diff)
downloadrails-cfd9d1d3e1e1d6bd51216d2e458337b5e904b7b0.tar.gz
rails-cfd9d1d3e1e1d6bd51216d2e458337b5e904b7b0.tar.bz2
rails-cfd9d1d3e1e1d6bd51216d2e458337b5e904b7b0.zip
Merge pull request #15339 from sgrif/sg-mysql-booleans
Refactor the type casting of booleans in MySQL
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/quoting.rb12
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb19
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: