diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2016-10-20 09:21:16 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2016-10-20 09:27:14 -0700 |
commit | 1345511081a7b4562281cf77d9e5aeeae2d3eb02 (patch) | |
tree | 096baa62a2de20d572775128a958da30a6721b55 /activerecord/lib | |
parent | b10227728bc9aa21bfebb2e0bbc12f416122d278 (diff) | |
download | rails-1345511081a7b4562281cf77d9e5aeeae2d3eb02.tar.gz rails-1345511081a7b4562281cf77d9e5aeeae2d3eb02.tar.bz2 rails-1345511081a7b4562281cf77d9e5aeeae2d3eb02.zip |
Use old typecasting method if no type casted binds are passed in
Query cache doesn't type cast bind parameters since it isn't
actually querying the database, so it can't pass those values in. Type
casting in the query cache method would cause the values to be type cast
twice in the case that there is a cache miss (since the methods it calls
will type cast *again*). If logging is disabled, then adding the type
cast code to the query cache method will needlessly typecast the values
(since the only reason those values are type cast is for display in the
logs).
Fixes #26828.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/log_subscriber.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb index ca9143c57d..4b8d8d9105 100644 --- a/activerecord/lib/active_record/log_subscriber.rb +++ b/activerecord/lib/active_record/log_subscriber.rb @@ -29,7 +29,8 @@ module ActiveRecord binds = nil unless (payload[:binds] || []).empty? - binds = " " + payload[:binds].zip(payload[:type_casted_binds]).map { |attr, value| + casted_params = type_casted_binds(payload[:binds], payload[:type_casted_binds]) + binds = " " + payload[:binds].zip(casted_params).map { |attr, value| render_bind(attr, value) }.inspect end @@ -42,6 +43,10 @@ module ActiveRecord private + def type_casted_binds(binds, casted_binds) + casted_binds || binds.map { |attr| type_cast attr.value_for_database } + end + def render_bind(attr, type_casted_value) value = if attr.type.binary? && attr.value "<#{attr.value_for_database.to_s.bytesize} bytes of binary data>" @@ -84,6 +89,10 @@ module ActiveRecord def logger ActiveRecord::Base.logger end + + def type_cast(value) + ActiveRecord::Base.connection.type_cast(value) + end end end |