From 1c60e5ef424d4a6638f1dc282db633b96daa12db Mon Sep 17 00:00:00 2001 From: Jason Abbott Date: Tue, 16 Jul 2024 16:51:50 -0600 Subject: [PATCH 1/3] Show trigger comments for expanded statement tracing --- GRDB/Core/Database.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 762ff7506b..e52c58052a 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -2101,6 +2101,10 @@ extension Database { /// information from leaking in unexpected locations, so use this /// property with care. public var expandedSQL: String { + if let unexpandedSQL { + let sql = String(cString: unexpandedSQL) + if sql.hasSuffix("--") { return sql } + } guard let cString = sqlite3_expanded_sql(sqliteStatement) else { return "" } From 802b4ca78a9018dc983d459b1a16f1a40b0d9f60 Mon Sep 17 00:00:00 2001 From: Jason Abbott Date: Tue, 16 Jul 2024 16:57:57 -0600 Subject: [PATCH 2/3] Correct suffix/prefix test --- GRDB/Core/Database.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index e52c58052a..c7708f67b7 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -2103,7 +2103,7 @@ extension Database { public var expandedSQL: String { if let unexpandedSQL { let sql = String(cString: unexpandedSQL) - if sql.hasSuffix("--") { return sql } + if sql.hasPrefix("--") { return sql } } guard let cString = sqlite3_expanded_sql(sqliteStatement) else { return "" From 14d2b931a4bbc9321bfd6a11ba0be691053f0215 Mon Sep 17 00:00:00 2001 From: Jason Abbott Date: Wed, 17 Jul 2024 09:17:03 -0600 Subject: [PATCH 3/3] Also return untrimmed comments when tracing without visible values --- GRDB/Core/Database.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index c7708f67b7..6281109b31 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -2083,7 +2083,8 @@ extension Database { /// ``` public var sql: String { if let unexpandedSQL { - return String(cString: unexpandedSQL).trimmedSQLStatement + let sql = String(cString: unexpandedSQL) + return sql.hasPrefix("--") ? sql : sql.trimmedSQLStatement } else { return String(cString: sqlite3_sql(sqliteStatement)).trimmedSQLStatement }