1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

cache connection when quoting

[#3642 state:committed]

Signed-off-by: Marius Nuennerich <marius@nuenneri.ch>
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
Comron Sattari 2010-05-02 13:09:22 +02:00 committed by Jeremy Kemper
parent 6b4e0cc526
commit e1a340a91d

View file

@ -1362,7 +1362,8 @@ module ActiveRecord #:nodoc:
def replace_bind_variables(statement, values) #:nodoc: def replace_bind_variables(statement, values) #:nodoc:
raise_if_bind_arity_mismatch(statement, statement.count('?'), values.size) raise_if_bind_arity_mismatch(statement, statement.count('?'), values.size)
bound = values.dup bound = values.dup
statement.gsub('?') { quote_bound_value(bound.shift) } c = connection
statement.gsub('?') { quote_bound_value(bound.shift, c) }
end end
def replace_named_bind_variables(statement, bind_vars) #:nodoc: def replace_named_bind_variables(statement, bind_vars) #:nodoc:
@ -1394,15 +1395,15 @@ module ActiveRecord #:nodoc:
expanded expanded
end end
def quote_bound_value(value) #:nodoc: def quote_bound_value(value, c = connection) #:nodoc:
if value.respond_to?(:map) && !value.acts_like?(:string) if value.respond_to?(:map) && !value.acts_like?(:string)
if value.respond_to?(:empty?) && value.empty? if value.respond_to?(:empty?) && value.empty?
connection.quote(nil) c.quote(nil)
else else
value.map { |v| connection.quote(v) }.join(',') value.map { |v| c.quote(v) }.join(',')
end end
else else
connection.quote(value) c.quote(value)
end end
end end