Refactor the type casting of booleans in MySQL
This commit is contained in:
parent
7a5fbaf02c
commit
fbdd58081e
@ -55,8 +55,8 @@ def type_cast(value, column)
|
||||
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 @@ def quoted_true
|
||||
"'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
|
||||
|
@ -178,17 +178,6 @@ def supports_index_sort_order?
|
||||
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 @@ def quoted_true
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user