Skip to content

Commit 03afbc3

Browse files
committed
Use TRUE and FALSE boolean literals for MySQL
Since rails#29699, abstract boolean serialization has been changed to use `TRUE` and `FALSE` literals. MySQL also support the literals. So we can use the abstract boolean serialization even for MySQL.
1 parent 526d4b8 commit 03afbc3

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require_relative "abstract_adapter"
24
require_relative "statement_pool"
35
require_relative "mysql/column"
@@ -861,8 +863,8 @@ def version_string
861863
class MysqlString < Type::String # :nodoc:
862864
def serialize(value)
863865
case value
864-
when true then MySQL::Quoting::QUOTED_TRUE
865-
when false then MySQL::Quoting::QUOTED_FALSE
866+
when true then "1"
867+
when false then "0"
866868
else super
867869
end
868870
end
@@ -871,8 +873,8 @@ def serialize(value)
871873

872874
def cast_value(value)
873875
case value
874-
when true then MySQL::Quoting::QUOTED_TRUE
875-
when false then MySQL::Quoting::QUOTED_FALSE
876+
when true then "1"
877+
when false then "0"
876878
else super
877879
end
878880
end

activerecord/lib/active_record/connection_adapters/mysql/quoting.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ module ActiveRecord
22
module ConnectionAdapters
33
module MySQL
44
module Quoting # :nodoc:
5-
QUOTED_TRUE, QUOTED_FALSE = "1".freeze, "0".freeze
6-
75
def quote_column_name(name)
86
@quoted_column_names[name] ||= "`#{super.gsub('`', '``')}`".freeze
97
end
@@ -12,18 +10,10 @@ def quote_table_name(name)
1210
@quoted_table_names[name] ||= super.gsub(".", "`.`").freeze
1311
end
1412

15-
def quoted_true
16-
QUOTED_TRUE
17-
end
18-
1913
def unquoted_true
2014
1
2115
end
2216

23-
def quoted_false
24-
QUOTED_FALSE
25-
end
26-
2717
def unquoted_false
2818
0
2919
end

0 commit comments

Comments
 (0)