diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-06-19 05:14:43 -0700 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-06-19 05:14:43 -0700 |
commit | 33c1b466447f3413654ddb158cb5111a200e23f1 (patch) | |
tree | 456acb189b768bfd8f176439f471fc642ec5e5c5 | |
parent | 615ad884579f416a7cfcd685a9aa9d124ab72a7a (diff) | |
parent | 6fb5f6f3d69662cc55a086f84f9caaca3eec1515 (diff) | |
download | rails-33c1b466447f3413654ddb158cb5111a200e23f1.tar.gz rails-33c1b466447f3413654ddb158cb5111a200e23f1.tar.bz2 rails-33c1b466447f3413654ddb158cb5111a200e23f1.zip |
Merge pull request #10991 from neerajdotname/10982
log the sql that is actually sent to the database
-rw-r--r-- | activerecord/CHANGELOG.md | 11 | ||||
-rw-r--r-- | activerecord/lib/active_record/log_subscriber.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/log_subscriber_test.rb | 7 |
3 files changed, 19 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 2f85a2ddae..933ac9fa6c 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,14 @@ +* Log the sql that is actually sent to the database. + + If I have a query that produces sql + `WHERE "users"."name" = 'a b'` then in the log all the + whitespace is being squeezed. So the sql that is printed in the + log is `WHERE "users"."name" = 'a b'`. + + Do not squeeze whitespace out of sql queries. Fixes #10982. + + *Neeraj Singh* + * Do not load all child records for inverse case. currently `post.comments.find(Comment.first.id)` would load all diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb index 61e5c120df..0358a36b14 100644 --- a/activerecord/lib/active_record/log_subscriber.rb +++ b/activerecord/lib/active_record/log_subscriber.rb @@ -41,7 +41,7 @@ module ActiveRecord return if IGNORE_PAYLOAD_NAMES.include?(payload[:name]) name = "#{payload[:name]} (#{event.duration.round(1)}ms)" - sql = payload[:sql].squeeze(' ') + sql = payload[:sql] binds = nil unless (payload[:binds] || []).empty? diff --git a/activerecord/test/cases/log_subscriber_test.rb b/activerecord/test/cases/log_subscriber_test.rb index 57eac0c175..3bdc5a1302 100644 --- a/activerecord/test/cases/log_subscriber_test.rb +++ b/activerecord/test/cases/log_subscriber_test.rb @@ -56,6 +56,13 @@ class LogSubscriberTest < ActiveRecord::TestCase assert_equal 2, logger.debugs.length end + def test_sql_statements_are_not_squeezed + event = Struct.new(:duration, :payload) + logger = TestDebugLogSubscriber.new + logger.sql(event.new(0, sql: 'ruby rails')) + assert_match(/ruby rails/, logger.debugs.first) + end + def test_ignore_binds_payload_with_nil_column event = Struct.new(:duration, :payload) |