From 1345511081a7b4562281cf77d9e5aeeae2d3eb02 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 20 Oct 2016 09:21:16 -0700 Subject: 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. --- activerecord/lib/active_record/log_subscriber.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/log_subscriber.rb') 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 -- cgit v1.2.3