mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Failing test for cached select statements that have failed
This commit is contained in:
1 parent
341bedd7ca
commit
92d78515c4
1 file changed
+18
-16
@@ -107,30 +107,32 @@ class SelectStatementTests : GRDBTestCase {
|
||||
func testCachedSelectStatementStepFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(table: "table1") { t in
|
||||
t.column("name", .text)
|
||||
var needsThrow = false
|
||||
dbQueue.add(function: DatabaseFunction("bomb", argumentCount: 0, pure: false) { _ in
|
||||
if needsThrow {
|
||||
throw DatabaseError(message: "boom")
|
||||
}
|
||||
try db.execute("INSERT INTO table1 (name) VALUES (?)", arguments: ["success"])
|
||||
let statement = try db.cachedSelectStatement("SELECT * FROM table1")
|
||||
XCTAssertEqual(try String.fetchAll(statement), ["success"])
|
||||
return "success"
|
||||
})
|
||||
try dbQueue.inDatabase { db in
|
||||
let sql = "SELECT bomb()"
|
||||
|
||||
needsThrow = false
|
||||
XCTAssertEqual(try String.fetchAll(db.cachedSelectStatement(sql)), ["success"])
|
||||
|
||||
try db.execute("DROP TABLE table1")
|
||||
do {
|
||||
_ = try String.fetchAll(statement)
|
||||
needsThrow = true
|
||||
_ = try String.fetchAll(db.cachedSelectStatement(sql))
|
||||
XCTFail()
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.code, 1)
|
||||
XCTAssertEqual(error.message!, "no such table: table1")
|
||||
XCTAssertEqual(error.sql!, "SELECT * FROM table1")
|
||||
XCTAssertEqual(error.description, "SQLite error 1 with statement `SELECT * FROM table1`: no such table: table1")
|
||||
XCTAssertEqual(error.message!, "boom")
|
||||
XCTAssertEqual(error.sql!, sql)
|
||||
XCTAssertEqual(error.description, "SQLite error 1 with statement `\(sql)`: boom")
|
||||
}
|
||||
|
||||
try db.create(table: "table1") { t in
|
||||
t.column("name", .text)
|
||||
}
|
||||
try db.execute("INSERT INTO table1 (name) VALUES (?)", arguments: ["success"])
|
||||
XCTAssertEqual(try String.fetchAll(statement), ["success"])
|
||||
needsThrow = false
|
||||
XCTAssertEqual(try String.fetchAll(db.cachedSelectStatement(sql)), ["success"])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user