Skip to content

Commit 2d96f05

Browse files
committed
Add SQLStatement.sql
1 parent 2d4950c commit 2d96f05

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Sources/SwiftSQL/SQLStatement.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,15 @@ public final class SQLStatement {
5555

5656
/// Returns true (non-zero) if the statement has been stepped at least once
5757
/// using `next()`, but has neither run to completion nor been reset.
58-
public var isBusy: Bool {
59-
sqlite3_stmt_busy(ref) != 0
60-
}
58+
public var isBusy: Bool { sqlite3_stmt_busy(ref) != 0 }
6159

6260
/// Returns true if the statement makes no direct changes to the content of the database file.
6361
///
6462
/// - note: For more information see [documentation](https://www.sqlite.org/c3ref/stmt_readonly.html).
65-
public var isReadOnly: Bool {
66-
sqlite3_stmt_readonly(ref) != 0
67-
}
63+
public var isReadOnly: Bool { sqlite3_stmt_readonly(ref) != 0 }
64+
65+
/// Returns the SQL text used to create the statement.
66+
public var sql: String { String(cString: sqlite3_sql(ref)) }
6867

6968
init(db: SQLConnection, ref: OpaquePointer) {
7069
self.db = db

Tests/SwiftSQLTests/SQLStatementTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,17 @@ final class SQLStatementTests: XCTestCase {
251251
User(name: "Bob", level: 90)
252252
])
253253
}
254+
255+
// MARK: Misc
256+
257+
func testSQL() throws {
258+
// GIVEN
259+
try db.createTables()
260+
let statement = try db.statement("SELECT * FROM Users")
261+
262+
// THEN
263+
XCTAssertEqual(statement.sql, "SELECT * FROM Users")
264+
}
254265
}
255266

256267
private extension SQLConnection {

0 commit comments

Comments
 (0)