Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show comments when tracing expanded statements #1575

Merged
merged 3 commits into from
Jul 17, 2024

Conversation

Jason-Abbott
Copy link
Contributor

@Jason-Abbott Jason-Abbott commented Jul 16, 2024

When trace logs are enabled along with public statements, the output repeats the triggering statement for every table trigger rather than showing the trace trigger comment.

For example, if table foo has two triggers and I do

INSERT INTO foo (one, two) VALUES (1, 2)

the current implementation will log

INSERT INTO foo (one, two) VALUES (1, 2)
INSERT INTO foo (one, two) VALUES (1, 2)
INSERT INTO foo (one, two) VALUES (1, 2)

rather than

INSERT INTO foo (one, two) VALUES (1, 2)
— TRIGGER <trigger name>
— TRIGGER <trigger name>

I am not experienced with C interop so welcome a more efficient way to test for a SQL comment. Also, I didn’t see that this warranted particular documentation since it will just match the behavior of the non-expanded traces.

Pull Request Checklist

  • CONTRIBUTING: You have read https://github.com/groue/GRDB.swift/blob/master/CONTRIBUTING.md
  • BRANCH: This pull request is submitted against the development branch.
  • DOCUMENTATION: Inline documentation has been updated.
  • DOCUMENTATION: README.md or another dedicated guide has been updated.
  • TESTS: Changes are tested.
  • TESTS: The make smokeTest terminal command runs without failure.

@groue
Copy link
Owner

groue commented Jul 17, 2024

Hello @Jason-Abbott,

Thank you for this contribution! I understand the itch scratched by this pull request. Traces prefixed with "--" also happen with virtual tables (full text search, for example). Those lines are a useful debugging tool, and I was unaware that expanded SQL would hide them by default.

May I suggest that we take the opportunity to improve the implementation of sql, a few lines above, with an extra commit named "Don't alter trace comments prefixed with --"? This will also make sure both accessors sql and expandedSQL return the same, unprocessed, comment.

 public var sql: String {
     if let unexpandedSQL {
-        return String(cString: unexpandedSQL).trimmedSQLStatement
+        let sql = String(cString: unexpandedSQL)
+        if sql.hasPrefix("--") {
+            return sql
+        } else {
+            return sql.trimmedSQLStatement
+        }
     } else {
         return String(cString: sqlite3_sql(sqliteStatement)).trimmedSQLStatement
     }
 }

I'm looking forward to merging this PR :-)

@Jason-Abbott
Copy link
Contributor Author

Done!

@groue
Copy link
Owner

groue commented Jul 17, 2024

Thank you Jason! Let's wait for the CI and I'll merge shortly 🙂

@groue groue merged commit 9f16865 into groue:development Jul 17, 2024
21 checks passed
@groue groue changed the title Show trigger comments for expanded statement tracing Show comments when tracing expanded statements Jul 20, 2024
@groue
Copy link
Owner

groue commented Jul 20, 2024

Shipped in v6.29.0 ⛵

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants