Permalink
Browse files

Merge pull request #10991 from neerajdotname/10982

log the sql that is actually sent to the database
  • Loading branch information...
2 parents 615ad88 + 6fb5f6f commit 33c1b466447f3413654ddb158cb5111a200e23f1 @senny senny committed Jun 19, 2013
View
@@ -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
@@ -41,7 +41,7 @@ def sql(event)
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?
@@ -56,6 +56,13 @@ def test_schema_statements_are_ignored
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)

0 comments on commit 33c1b46

Please sign in to comment.