Skip to content

Commit 2f60a75

Browse files
authored
Merge pull request rails#26630 from kamipo/quoted_binary
Extract `quoted_binary` and use it rather than override `_quote`
2 parents c6b4b4a + 4a4286a commit 2f60a75

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ def quoted_time(value) # :nodoc:
141141
quoted_date(value).sub(/\A2000-01-01 /, "")
142142
end
143143

144+
def quoted_binary(value) # :nodoc:
145+
"'#{quote_string(value.to_s)}'"
146+
end
147+
144148
private
145149

146150
def type_casted_binds(binds)
@@ -153,14 +157,15 @@ def types_which_need_no_typecasting
153157

154158
def _quote(value)
155159
case value
156-
when String, ActiveSupport::Multibyte::Chars, Type::Binary::Data
160+
when String, ActiveSupport::Multibyte::Chars
157161
"'#{quote_string(value.to_s)}'"
158162
when true then quoted_true
159163
when false then quoted_false
160164
when nil then "NULL"
161165
# BigDecimals need to be put in a non-normalized form and quoted.
162166
when BigDecimal then value.to_s("F")
163167
when Numeric, ActiveSupport::Duration then value.to_s
168+
when Type::Binary::Data then quoted_binary(value)
164169
when Type::Time::Value then "'#{quoted_time(value)}'"
165170
when Date, Time then "'#{quoted_date(value)}'"
166171
when Symbol then "'#{quote_string(value.to_s)}'"

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,9 @@ def quoted_date(value)
3636
end
3737
end
3838

39-
private
40-
41-
def _quote(value)
42-
if value.is_a?(Type::Binary::Data)
43-
"x'#{value.hex}'"
44-
else
45-
super
46-
end
47-
end
39+
def quoted_binary(value)
40+
"x'#{value.hex}'"
41+
end
4842
end
4943
end
5044
end

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def quoted_date(value) #:nodoc:
5555
end
5656
end
5757

58+
def quoted_binary(value) # :nodoc:
59+
"'#{escape_bytea(value.to_s)}'"
60+
end
61+
5862
def quote_default_expression(value, column) # :nodoc:
5963
if value.is_a?(Proc)
6064
value.call
@@ -76,8 +80,6 @@ def lookup_cast_type_from_column(column) # :nodoc:
7680

7781
def _quote(value)
7882
case value
79-
when Type::Binary::Data
80-
"'#{escape_bytea(value.to_s)}'"
8183
when OID::Xml::Data
8284
"xml '#{quote_string(value.to_s)}'"
8385
when OID::Bit::Data

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@ def quoted_time(value)
1818
quoted_date(value)
1919
end
2020

21-
private
21+
def quoted_binary(value)
22+
"x'#{value.hex}'"
23+
end
2224

23-
def _quote(value)
24-
if value.is_a?(Type::Binary::Data)
25-
"x'#{value.hex}'"
26-
else
27-
super
28-
end
29-
end
25+
private
3026

3127
def _type_cast(value)
3228
case value

0 commit comments

Comments
 (0)