mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
TraceEvent.description no longer contains statement arguments
Use TraceEvent.expandedDescription in order to see statements arguments
This commit is contained in:
1 parent
9f0ba49c93
commit
d3985c7ebf
3 files changed
+44
-5
No files matched your search
@@ -1714,7 +1714,37 @@ extension Database {
|
||||
/// An event reported by `TracingOptions.profile`.
|
||||
case profile(statement: Statement, duration: TimeInterval)
|
||||
|
||||
/// The trace event description.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// SELECT * FROM player WHERE id = ?
|
||||
/// 0.1s SELECT * FROM player WHERE id = ?
|
||||
///
|
||||
/// The format of the event description may change between GRDB releases,
|
||||
/// without notice: don't have your application rely on any specific format.
|
||||
public var description: String {
|
||||
// TODO: consider including arguments depending on database configuration,
|
||||
// for easy verbose debugging when the database does not contain sensitive information.
|
||||
switch self {
|
||||
case let .statement(statement):
|
||||
return statement.sql
|
||||
case let .profile(statement: statement, duration: duration):
|
||||
let durationString = String(format: "%.3f", duration)
|
||||
return "\(durationString)s \(statement.sql)"
|
||||
}
|
||||
}
|
||||
|
||||
/// The trace event description, where bound parameters are expanded.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// SELECT * FROM player WHERE id = 1
|
||||
/// 0.1s SELECT * FROM player WHERE id = 1
|
||||
///
|
||||
/// The format of the event description may change between GRDB releases,
|
||||
/// without notice: don't have your application rely on any specific format.
|
||||
public var expandedDescription: String {
|
||||
switch self {
|
||||
case let .statement(statement):
|
||||
return statement.expandedSQL
|
||||
|
||||
@@ -31,8 +31,10 @@ class DatabaseTraceTests : GRDBTestCase {
|
||||
try dbQueue.inDatabase { db in
|
||||
var lastSQL: String?
|
||||
var lastDescription: String?
|
||||
var lastExpandedDescription: String?
|
||||
db.trace(options: .statement) { event in
|
||||
lastDescription = event.description
|
||||
lastExpandedDescription = event.expandedDescription
|
||||
switch event {
|
||||
case let .statement(statement):
|
||||
lastSQL = statement.sql
|
||||
@@ -43,10 +45,12 @@ class DatabaseTraceTests : GRDBTestCase {
|
||||
try db.execute(sql: "CREATE table t(a);")
|
||||
XCTAssertEqual(lastSQL, "CREATE table t(a)")
|
||||
XCTAssertEqual(lastDescription, "CREATE table t(a)")
|
||||
XCTAssertEqual(lastExpandedDescription, "CREATE table t(a)")
|
||||
|
||||
try db.execute(sql: "INSERT INTO t (a) VALUES (?)", arguments: [1])
|
||||
XCTAssertEqual(lastSQL, "INSERT INTO t (a) VALUES (?)")
|
||||
XCTAssertEqual(lastDescription, "INSERT INTO t (a) VALUES (1)")
|
||||
XCTAssertEqual(lastDescription, "INSERT INTO t (a) VALUES (?)")
|
||||
XCTAssertEqual(lastExpandedDescription, "INSERT INTO t (a) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,8 +65,10 @@ class DatabaseTraceTests : GRDBTestCase {
|
||||
var lastExpandedSQL: String?
|
||||
var lastDuration: TimeInterval?
|
||||
var lastDescription: String?
|
||||
var lastExpandedDescription: String?
|
||||
db.trace(options: .profile) { event in
|
||||
lastDescription = event.description
|
||||
lastExpandedDescription = event.expandedDescription
|
||||
switch event {
|
||||
case let .profile(statement: statement, duration: duration):
|
||||
lastSQL = statement.sql
|
||||
@@ -77,12 +83,14 @@ class DatabaseTraceTests : GRDBTestCase {
|
||||
XCTAssertEqual(lastExpandedSQL, "CREATE table t(a)")
|
||||
XCTAssertTrue(lastDuration! >= 0)
|
||||
XCTAssert(lastDescription!.hasSuffix("s CREATE table t(a)"))
|
||||
XCTAssert(lastExpandedDescription!.hasSuffix("s CREATE table t(a)"))
|
||||
|
||||
try db.execute(sql: "INSERT INTO t (a) VALUES (?)", arguments: [1])
|
||||
XCTAssertEqual(lastSQL, "INSERT INTO t (a) VALUES (?)")
|
||||
XCTAssertEqual(lastExpandedSQL, "INSERT INTO t (a) VALUES (1)")
|
||||
XCTAssertTrue(lastDuration! >= 0)
|
||||
XCTAssert(lastDescription!.hasSuffix("s INSERT INTO t (a) VALUES (1)"))
|
||||
XCTAssert(lastDescription!.hasSuffix("s INSERT INTO t (a) VALUES (?)"))
|
||||
XCTAssert(lastExpandedDescription!.hasSuffix("s INSERT INTO t (a) VALUES (1)"))
|
||||
|
||||
db.add(function: DatabaseFunction("wait", argumentCount: 1, pure: true, function: { dbValues in
|
||||
if let delay = TimeInterval.fromDatabaseValue(dbValues[0]) {
|
||||
@@ -96,7 +104,8 @@ class DatabaseTraceTests : GRDBTestCase {
|
||||
XCTAssertEqual(lastExpandedSQL, "SELECT wait(0.5)")
|
||||
XCTAssertGreaterThan(lastDuration!, 0.4)
|
||||
XCTAssertLessThan(lastDuration!, 2) // Travis can be so slow
|
||||
XCTAssert(lastDescription!.hasSuffix("s SELECT wait(0.5)"))
|
||||
XCTAssert(lastDescription!.hasSuffix("s SELECT wait(?)"))
|
||||
XCTAssert(lastExpandedDescription!.hasSuffix("s SELECT wait(0.5)"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +141,7 @@ class DatabaseTraceTests : GRDBTestCase {
|
||||
""", arguments: [1])
|
||||
XCTAssertEqual(events.suffix(2), [
|
||||
"SQL: CREATE table t(a)",
|
||||
"SQL: INSERT INTO t (a) VALUES (1)"])
|
||||
"SQL: INSERT INTO t (a) VALUES (?)"])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ class GRDBTestCase: XCTestCase {
|
||||
|
||||
dbConfiguration.prepareDatabase { db in
|
||||
db.trace { event in
|
||||
self.sqlQueries.append(event.description)
|
||||
self.sqlQueries.append(event.expandedDescription)
|
||||
}
|
||||
|
||||
#if GRDBCIPHER_USE_ENCRYPTION
|
||||
|
||||
Reference in new issue
Block a user