mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #41068 from ricardotk002/fix-where-in-stmt-logging
Fix binds logging for "WHERE ... IN ..." statements
This commit is contained in:
commit
b5c4af7d52
8 changed files with 20 additions and 10 deletions
|
@ -80,8 +80,8 @@ module ActiveRecord
|
|||
self
|
||||
end
|
||||
|
||||
def add_binds(binds)
|
||||
@binds.concat binds
|
||||
def add_binds(binds, proc_for_binds = nil)
|
||||
@binds.concat proc_for_binds ? binds.map(&proc_for_binds) : binds
|
||||
binds.size.times do |i|
|
||||
@parts << ", " unless i == 0
|
||||
@parts << Substitute.new
|
||||
|
|
|
@ -16,8 +16,8 @@ module Arel # :nodoc: all
|
|||
self
|
||||
end
|
||||
|
||||
def add_binds(binds)
|
||||
@binds.concat binds
|
||||
def add_binds(binds, proc_for_binds = nil)
|
||||
@binds.concat proc_for_binds ? binds.map(&proc_for_binds) : binds
|
||||
self
|
||||
end
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@ module Arel # :nodoc: all
|
|||
self
|
||||
end
|
||||
|
||||
def add_binds(binds, &block)
|
||||
left.add_binds(binds, &block)
|
||||
right.add_binds(binds, &block)
|
||||
def add_binds(binds, proc_for_binds = nil, &block)
|
||||
left.add_binds(binds, proc_for_binds, &block)
|
||||
right.add_binds(binds, proc_for_binds, &block)
|
||||
self
|
||||
end
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ module Arel # :nodoc: all
|
|||
self
|
||||
end
|
||||
|
||||
def add_binds(binds, &block)
|
||||
def add_binds(binds, proc_for_binds = nil, &block)
|
||||
self << (@bind_index...@bind_index += binds.size).map(&block).join(", ")
|
||||
self
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ module Arel # :nodoc: all
|
|||
self << quoter.quote(bind)
|
||||
end
|
||||
|
||||
def add_binds(binds)
|
||||
def add_binds(binds, proc_for_binds = nil)
|
||||
self << binds.map { |bind| quoter.quote(bind) }.join(", ")
|
||||
end
|
||||
|
||||
|
|
|
@ -55,6 +55,10 @@ module Arel # :nodoc: all
|
|||
casted_values
|
||||
end
|
||||
|
||||
def proc_for_binds
|
||||
-> value { ActiveModel::Attribute.with_cast_value(attribute.name, value, attribute.type_caster) }
|
||||
end
|
||||
|
||||
def fetch_attribute(&block)
|
||||
if attribute
|
||||
yield attribute
|
||||
|
|
|
@ -337,7 +337,7 @@ module Arel # :nodoc: all
|
|||
if values.empty?
|
||||
collector << @connection.quote(nil)
|
||||
else
|
||||
collector.add_binds(values, &bind_block)
|
||||
collector.add_binds(values, o.proc_for_binds, &bind_block)
|
||||
end
|
||||
|
||||
collector << ")"
|
||||
|
|
|
@ -246,6 +246,12 @@ class LogSubscriberTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
if ActiveRecord::Base.connection.prepared_statements
|
||||
def test_where_in_binds_logging_include_attribute_names
|
||||
Developer.where(id: [1, 2, 3, 4, 5]).load
|
||||
wait
|
||||
assert_match(%{["id", 1], ["id", 2], ["id", 3], ["id", 4], ["id", 5]}, @logger.logged(:debug).last)
|
||||
end
|
||||
|
||||
def test_binary_data_is_not_logged
|
||||
Binary.create(data: "some binary data")
|
||||
wait
|
||||
|
|
Loading…
Reference in a new issue