mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
#147: fetchCursor, fetchAll & fetchOne all throw sqlite3_prepare_v2 errors, sqlite3_step errors, and conversion errors (for DatabaseValueConvertible)
This commit is contained in:
1 parent
35414e0afd
commit
bbe0bfadd9
4 files changed
+515
-100
No files matched your search
@@ -1,5 +1,4 @@
|
||||
- [ ] Explain that RowConvertible.init() does not throw because it would prevent FetchedRecordsController from lazily instantiating records as they are needed by the table view.
|
||||
- [ ] DatabaseCursor: test that Row.fetchAll(db, "SELECT * FROM boooks") throws a catchable error
|
||||
- [ ] DatabaseCursor/FetchedRecordsController: handle fetch errors
|
||||
- [ ] Swift 3.0.2 (Xcode 8.2): "Type inference will properly unwrap optionals when used with generics and implicitly-unwrapped optionals." Maybe this fixes `row.value(named: "foo") as? Int`?
|
||||
- [ ] Refactor Database notion of transaction/savepoints into a single type. Support INSERT OR ROLLBACK.
|
||||
|
||||
+202
-42
@@ -25,10 +25,10 @@ private struct WrappedInt: DatabaseValueConvertible {
|
||||
}
|
||||
|
||||
private struct Request : FetchRequest {
|
||||
let statement: SelectStatement
|
||||
let statement: () throws -> SelectStatement
|
||||
let adapter: RowAdapter?
|
||||
func prepare(_ db: Database) -> (SelectStatement, RowAdapter?) {
|
||||
return (statement, adapter)
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return (try statement(), adapter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(WrappedInt.fetchCursor(db, sql))
|
||||
try test(WrappedInt.fetchCursor(statement))
|
||||
try test(WrappedInt.fetchCursor(db, Request(statement: statement, adapter: nil)))
|
||||
try test(WrappedInt.fetchCursor(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2"
|
||||
@@ -58,7 +58,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(WrappedInt.fetchCursor(db, sql, adapter: adapter))
|
||||
try test(WrappedInt.fetchCursor(statement, adapter: adapter))
|
||||
try test(WrappedInt.fetchCursor(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(WrappedInt.fetchCursor(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,7 +96,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(WrappedInt.fetchCursor(db, sql), sql: sql)
|
||||
try test(WrappedInt.fetchCursor(statement), sql: sql)
|
||||
try test(WrappedInt.fetchCursor(db, Request(statement: statement, adapter: nil)), sql: sql)
|
||||
try test(WrappedInt.fetchCursor(db, Request(statement: { statement }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL UNION ALL SELECT 0, 'foo' UNION ALL SELECT 0, 2"
|
||||
@@ -104,13 +104,13 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(WrappedInt.fetchCursor(db, sql, adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchCursor(statement, adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchCursor(db, Request(statement: statement, adapter: adapter)), sql: sql)
|
||||
try test(WrappedInt.fetchCursor(db, Request(statement: { statement }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchCursorSQLiteFailure() {
|
||||
func testFetchCursorStepFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
@@ -141,14 +141,46 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT 1 UNION ALL SELECT throw() UNION ALL SELECT 2"
|
||||
try test(WrappedInt.fetchCursor(db, sql), sql: sql)
|
||||
try test(WrappedInt.fetchCursor(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(WrappedInt.fetchCursor(db, Request(statement: db.makeSelectStatement(sql), adapter: nil)), sql: sql)
|
||||
try test(WrappedInt.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, throw() UNION ALL SELECT 0, 2"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(WrappedInt.fetchCursor(db, sql, adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchCursor(db, Request(statement: db.makeSelectStatement(sql), adapter: adapter)), sql: sql)
|
||||
try test(WrappedInt.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchCursorCompilationFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
func test(_ cursor: @autoclosure () throws -> DatabaseCursor<WrappedInt>, sql: String) throws {
|
||||
do {
|
||||
_ = try cursor()
|
||||
XCTFail()
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.code, 1) // SQLITE_ERROR
|
||||
XCTAssertEqual(error.message, "no such table: nonExistingTable")
|
||||
XCTAssertEqual(error.sql!, sql)
|
||||
XCTAssertEqual(error.description, "SQLite error 1 with statement `\(sql)`: no such table: nonExistingTable")
|
||||
}
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(WrappedInt.fetchCursor(db, sql), sql: sql)
|
||||
try test(WrappedInt.fetchCursor(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(WrappedInt.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(WrappedInt.fetchCursor(db, sql, adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,7 +198,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(WrappedInt.fetchAll(db, sql))
|
||||
try test(WrappedInt.fetchAll(statement))
|
||||
try test(WrappedInt.fetchAll(db, Request(statement: statement, adapter: nil)))
|
||||
try test(WrappedInt.fetchAll(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2"
|
||||
@@ -174,7 +206,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(WrappedInt.fetchAll(db, sql, adapter: adapter))
|
||||
try test(WrappedInt.fetchAll(statement, adapter: adapter))
|
||||
try test(WrappedInt.fetchAll(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(WrappedInt.fetchAll(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -200,7 +232,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(WrappedInt.fetchAll(db, sql), sql: sql)
|
||||
try test(WrappedInt.fetchAll(statement), sql: sql)
|
||||
try test(WrappedInt.fetchAll(db, Request(statement: statement, adapter: nil)), sql: sql)
|
||||
try test(WrappedInt.fetchAll(db, Request(statement: { statement }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL UNION ALL SELECT 0, 2"
|
||||
@@ -208,13 +240,13 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(WrappedInt.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchAll(statement, adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchAll(db, Request(statement: statement, adapter: adapter)), sql: sql)
|
||||
try test(WrappedInt.fetchAll(db, Request(statement: { statement }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchAllSQLiteFailure() {
|
||||
func testFetchAllStepFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
@@ -236,7 +268,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(WrappedInt.fetchAll(db, sql), sql: sql)
|
||||
try test(WrappedInt.fetchAll(statement), sql: sql)
|
||||
try test(WrappedInt.fetchAll(db, Request(statement: statement, adapter: nil)), sql: sql)
|
||||
try test(WrappedInt.fetchAll(db, Request(statement: { statement }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
@@ -244,7 +276,39 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(WrappedInt.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchAll(statement, adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchAll(db, Request(statement: statement, adapter: adapter)), sql: sql)
|
||||
try test(WrappedInt.fetchAll(db, Request(statement: { statement }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchAllCompilationFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
func test(_ array: @autoclosure () throws -> [WrappedInt], sql: String) throws {
|
||||
do {
|
||||
_ = try array()
|
||||
XCTFail()
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.code, 1) // SQLITE_ERROR
|
||||
XCTAssertEqual(error.message, "no such table: nonExistingTable")
|
||||
XCTAssertEqual(error.sql!, sql)
|
||||
XCTAssertEqual(error.description, "SQLite error 1 with statement `\(sql)`: no such table: nonExistingTable")
|
||||
}
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(WrappedInt.fetchAll(db, sql), sql: sql)
|
||||
try test(WrappedInt.fetchAll(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(WrappedInt.fetchAll(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(WrappedInt.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchAll(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -263,7 +327,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(WrappedInt.fetchOne(db, sql))
|
||||
try test(WrappedInt.fetchOne(statement))
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: statement, adapter: nil)))
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 WHERE 0"
|
||||
@@ -271,7 +335,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(WrappedInt.fetchOne(db, sql, adapter: adapter))
|
||||
try test(WrappedInt.fetchOne(statement, adapter: adapter))
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
do {
|
||||
@@ -283,7 +347,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(WrappedInt.fetchOne(db, sql))
|
||||
try test(WrappedInt.fetchOne(statement))
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: statement, adapter: nil)))
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, NULL"
|
||||
@@ -291,7 +355,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(WrappedInt.fetchOne(db, sql, adapter: adapter))
|
||||
try test(WrappedInt.fetchOne(statement, adapter: adapter))
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
do {
|
||||
@@ -303,7 +367,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(WrappedInt.fetchOne(db, sql))
|
||||
try test(WrappedInt.fetchOne(statement))
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: statement, adapter: nil)))
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1"
|
||||
@@ -311,7 +375,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(WrappedInt.fetchOne(db, sql, adapter: adapter))
|
||||
try test(WrappedInt.fetchOne(statement, adapter: adapter))
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -338,7 +402,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(WrappedInt.fetchOne(db, sql), sql: sql)
|
||||
try test(WrappedInt.fetchOne(statement), sql: sql)
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: statement, adapter: nil)), sql: sql)
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: { statement }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 'foo'"
|
||||
@@ -346,13 +410,13 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(WrappedInt.fetchOne(db, sql, adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchOne(statement, adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: statement, adapter: adapter)), sql: sql)
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: { statement }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchOneSQLiteFailure() {
|
||||
func testFetchOneStepFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
@@ -374,7 +438,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(WrappedInt.fetchOne(db, sql), sql: sql)
|
||||
try test(WrappedInt.fetchOne(statement), sql: sql)
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: statement, adapter: nil)), sql: sql)
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: { statement }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
@@ -382,7 +446,39 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(WrappedInt.fetchOne(db, sql, adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchOne(statement, adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: statement, adapter: adapter)), sql: sql)
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: { statement }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchOneCompilationFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
func test(_ value: @autoclosure () throws -> WrappedInt?, sql: String) throws {
|
||||
do {
|
||||
_ = try value()
|
||||
XCTFail()
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.code, 1) // SQLITE_ERROR
|
||||
XCTAssertEqual(error.message, "no such table: nonExistingTable")
|
||||
XCTAssertEqual(error.sql!, sql)
|
||||
XCTAssertEqual(error.description, "SQLite error 1 with statement `\(sql)`: no such table: nonExistingTable")
|
||||
}
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(WrappedInt.fetchOne(db, sql), sql: sql)
|
||||
try test(WrappedInt.fetchOne(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(WrappedInt.fetchOne(db, sql, adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(WrappedInt.fetchOne(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -404,7 +500,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, sql))
|
||||
try test(Optional<WrappedInt>.fetchCursor(statement))
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, Request(statement: statement, adapter: nil)))
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL"
|
||||
@@ -412,7 +508,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, sql, adapter: adapter))
|
||||
try test(Optional<WrappedInt>.fetchCursor(statement, adapter: adapter))
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -442,7 +538,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, sql), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(statement), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, Request(statement: statement, adapter: nil)), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, Request(statement: { statement }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL UNION ALL SELECT 0, 'foo' UNION ALL SELECT 0, 2"
|
||||
@@ -450,13 +546,13 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(statement, adapter: adapter), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, Request(statement: statement, adapter: adapter)), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, Request(statement: { statement }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testOptionalFetchCursorSQLiteFailure() {
|
||||
func testOptionalFetchCursorStepFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
@@ -487,14 +583,46 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT 1 UNION ALL SELECT throw() UNION ALL SELECT 2"
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, sql), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, Request(statement: db.makeSelectStatement(sql), adapter: nil)), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, throw() UNION ALL SELECT 0, 2"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, Request(statement: db.makeSelectStatement(sql), adapter: adapter)), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testOptionalFetchCursorCompilationFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
func test(_ cursor: @autoclosure () throws -> DatabaseCursor<WrappedInt?>, sql: String) throws {
|
||||
do {
|
||||
_ = try cursor()
|
||||
XCTFail()
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.code, 1) // SQLITE_ERROR
|
||||
XCTAssertEqual(error.message, "no such table: nonExistingTable")
|
||||
XCTAssertEqual(error.sql!, sql)
|
||||
XCTAssertEqual(error.description, "SQLite error 1 with statement `\(sql)`: no such table: nonExistingTable")
|
||||
}
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, sql), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -514,7 +642,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(db, sql))
|
||||
try test(Optional<WrappedInt>.fetchAll(statement))
|
||||
try test(Optional<WrappedInt>.fetchAll(db, Request(statement: statement, adapter: nil)))
|
||||
try test(Optional<WrappedInt>.fetchAll(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL"
|
||||
@@ -522,7 +650,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<WrappedInt>.fetchAll(db, sql, adapter: adapter))
|
||||
try test(Optional<WrappedInt>.fetchAll(statement, adapter: adapter))
|
||||
try test(Optional<WrappedInt>.fetchAll(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(Optional<WrappedInt>.fetchAll(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -548,7 +676,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(db, sql), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(statement), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(db, Request(statement: statement, adapter: nil)), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(db, Request(statement: { statement }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL UNION ALL SELECT 0, 'foo' UNION ALL SELECT 0, 2"
|
||||
@@ -556,13 +684,13 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<WrappedInt>.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(statement, adapter: adapter), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(db, Request(statement: statement, adapter: adapter)), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(db, Request(statement: { statement }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testOptionalFetchAllSQLiteFailure() {
|
||||
func testOptionalFetchAllStepFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
@@ -584,7 +712,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(db, sql), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(statement), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(db, Request(statement: statement, adapter: nil)), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(db, Request(statement: { statement }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
@@ -592,7 +720,39 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<WrappedInt>.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(statement, adapter: adapter), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(db, Request(statement: statement, adapter: adapter)), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(db, Request(statement: { statement }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testOptionalFetchAllCompilationFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
func test(_ array: @autoclosure () throws -> [WrappedInt?], sql: String) throws {
|
||||
do {
|
||||
_ = try array()
|
||||
XCTFail()
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.code, 1) // SQLITE_ERROR
|
||||
XCTAssertEqual(error.message, "no such table: nonExistingTable")
|
||||
XCTAssertEqual(error.sql!, sql)
|
||||
XCTAssertEqual(error.description, "SQLite error 1 with statement `\(sql)`: no such table: nonExistingTable")
|
||||
}
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(Optional<WrappedInt>.fetchAll(db, sql), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<WrappedInt>.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<WrappedInt>.fetchAll(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ extension SimpleRowConvertible : RowConvertible {
|
||||
}
|
||||
|
||||
private struct Request : FetchRequest {
|
||||
let statement: SelectStatement
|
||||
let statement: () throws -> SelectStatement
|
||||
let adapter: RowAdapter?
|
||||
func prepare(_ db: Database) -> (SelectStatement, RowAdapter?) {
|
||||
return (statement, adapter)
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return (try statement(), adapter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(SimpleRowConvertible.fetchCursor(db, sql))
|
||||
try test(SimpleRowConvertible.fetchCursor(statement))
|
||||
try test(SimpleRowConvertible.fetchCursor(db, Request(statement: statement, adapter: nil)))
|
||||
try test(SimpleRowConvertible.fetchCursor(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 0, 'Barbara', 'Gourde'"
|
||||
@@ -71,13 +71,13 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(SimpleRowConvertible.fetchCursor(db, sql, adapter: adapter))
|
||||
try test(SimpleRowConvertible.fetchCursor(statement, adapter: adapter))
|
||||
try test(SimpleRowConvertible.fetchCursor(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(SimpleRowConvertible.fetchCursor(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchCursorSQLiteFailure() {
|
||||
func testFetchCursorStepFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
@@ -111,14 +111,46 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let sql = "SELECT 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT throw(), NULL"
|
||||
try test(SimpleRowConvertible.fetchCursor(db, sql), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchCursor(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchCursor(db, Request(statement: db.makeSelectStatement(sql), adapter: nil)), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 0, throw(), NULL"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(SimpleRowConvertible.fetchCursor(db, sql, adapter: adapter), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchCursor(db, Request(statement: db.makeSelectStatement(sql), adapter: adapter)), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchCursorCompilationFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
func test(_ cursor: @autoclosure () throws -> DatabaseCursor<SimpleRowConvertible>, sql: String) throws {
|
||||
do {
|
||||
_ = try cursor()
|
||||
XCTFail()
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.code, 1) // SQLITE_ERROR
|
||||
XCTAssertEqual(error.message, "no such table: nonExistingTable")
|
||||
XCTAssertEqual(error.sql!, sql)
|
||||
XCTAssertEqual(error.description, "SQLite error 1 with statement `\(sql)`: no such table: nonExistingTable")
|
||||
}
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(SimpleRowConvertible.fetchCursor(db, sql), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchCursor(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(SimpleRowConvertible.fetchCursor(db, sql, adapter: adapter), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,7 +170,7 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(SimpleRowConvertible.fetchAll(db, sql))
|
||||
try test(SimpleRowConvertible.fetchAll(statement))
|
||||
try test(SimpleRowConvertible.fetchAll(db, Request(statement: statement, adapter: nil)))
|
||||
try test(SimpleRowConvertible.fetchAll(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 0, 'Barbara', 'Gourde'"
|
||||
@@ -146,13 +178,13 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(SimpleRowConvertible.fetchAll(db, sql, adapter: adapter))
|
||||
try test(SimpleRowConvertible.fetchAll(statement, adapter: adapter))
|
||||
try test(SimpleRowConvertible.fetchAll(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(SimpleRowConvertible.fetchAll(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchAllSQLiteFailure() {
|
||||
func testFetchAllStepFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
@@ -174,7 +206,7 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(SimpleRowConvertible.fetchAll(db, sql), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchAll(statement), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchAll(db, Request(statement: statement, adapter: nil)), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchAll(db, Request(statement: { statement }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
@@ -182,7 +214,39 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(SimpleRowConvertible.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchAll(statement, adapter: adapter), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchAll(db, Request(statement: statement, adapter: adapter)), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchAll(db, Request(statement: { statement }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchAllCompilationFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
func test(_ array: @autoclosure () throws -> [SimpleRowConvertible], sql: String) throws {
|
||||
do {
|
||||
_ = try array()
|
||||
XCTFail()
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.code, 1) // SQLITE_ERROR
|
||||
XCTAssertEqual(error.message, "no such table: nonExistingTable")
|
||||
XCTAssertEqual(error.sql!, sql)
|
||||
XCTAssertEqual(error.description, "SQLite error 1 with statement `\(sql)`: no such table: nonExistingTable")
|
||||
}
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(SimpleRowConvertible.fetchAll(db, sql), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchAll(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchAll(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(SimpleRowConvertible.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchAll(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -201,7 +265,7 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(SimpleRowConvertible.fetchOne(db, sql))
|
||||
try test(SimpleRowConvertible.fetchOne(statement))
|
||||
try test(SimpleRowConvertible.fetchOne(db, Request(statement: statement, adapter: nil)))
|
||||
try test(SimpleRowConvertible.fetchOne(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 WHERE 0"
|
||||
@@ -209,7 +273,7 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(SimpleRowConvertible.fetchOne(db, sql, adapter: adapter))
|
||||
try test(SimpleRowConvertible.fetchOne(statement, adapter: adapter))
|
||||
try test(SimpleRowConvertible.fetchOne(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(SimpleRowConvertible.fetchOne(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
do {
|
||||
@@ -223,7 +287,7 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(SimpleRowConvertible.fetchOne(db, sql))
|
||||
try test(SimpleRowConvertible.fetchOne(statement))
|
||||
try test(SimpleRowConvertible.fetchOne(db, Request(statement: statement, adapter: nil)))
|
||||
try test(SimpleRowConvertible.fetchOne(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName"
|
||||
@@ -231,14 +295,14 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(SimpleRowConvertible.fetchOne(db, sql, adapter: adapter))
|
||||
try test(SimpleRowConvertible.fetchOne(statement, adapter: adapter))
|
||||
try test(SimpleRowConvertible.fetchOne(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(SimpleRowConvertible.fetchOne(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchOneSQLiteFailure() {
|
||||
func testFetchOneStepFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
@@ -260,7 +324,7 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(SimpleRowConvertible.fetchOne(db, sql), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchOne(statement), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchOne(db, Request(statement: statement, adapter: nil)), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchOne(db, Request(statement: { statement }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
@@ -268,7 +332,39 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(SimpleRowConvertible.fetchOne(db, sql, adapter: adapter), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchOne(statement, adapter: adapter), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchOne(db, Request(statement: statement, adapter: adapter)), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchOne(db, Request(statement: { statement }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchOneCompilationFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
func test(_ value: @autoclosure () throws -> SimpleRowConvertible?, sql: String) throws {
|
||||
do {
|
||||
_ = try value()
|
||||
XCTFail()
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.code, 1) // SQLITE_ERROR
|
||||
XCTAssertEqual(error.message, "no such table: nonExistingTable")
|
||||
XCTAssertEqual(error.sql!, sql)
|
||||
XCTAssertEqual(error.description, "SQLite error 1 with statement `\(sql)`: no such table: nonExistingTable")
|
||||
}
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(SimpleRowConvertible.fetchOne(db, sql), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchOne(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchOne(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(SimpleRowConvertible.fetchOne(db, sql, adapter: adapter), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(SimpleRowConvertible.fetchOne(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+197
-37
@@ -52,10 +52,10 @@ private struct FastWrappedInt: DatabaseValueConvertible, StatementColumnConverti
|
||||
}
|
||||
|
||||
private struct Request : FetchRequest {
|
||||
let statement: SelectStatement
|
||||
let statement: () throws -> SelectStatement
|
||||
let adapter: RowAdapter?
|
||||
func prepare(_ db: Database) -> (SelectStatement, RowAdapter?) {
|
||||
return (statement, adapter)
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return (try statement(), adapter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(FastWrappedInt.fetchCursor(db, sql))
|
||||
try test(FastWrappedInt.fetchCursor(statement))
|
||||
try test(FastWrappedInt.fetchCursor(db, Request(statement: statement, adapter: nil)))
|
||||
try test(FastWrappedInt.fetchCursor(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2"
|
||||
@@ -132,7 +132,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(FastWrappedInt.fetchCursor(db, sql, adapter: adapter))
|
||||
try test(FastWrappedInt.fetchCursor(statement, adapter: adapter))
|
||||
try test(FastWrappedInt.fetchCursor(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(FastWrappedInt.fetchCursor(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,7 +168,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(FastWrappedInt.fetchCursor(db, sql), sql: sql)
|
||||
try test(FastWrappedInt.fetchCursor(statement), sql: sql)
|
||||
try test(FastWrappedInt.fetchCursor(db, Request(statement: statement, adapter: nil)), sql: sql)
|
||||
try test(FastWrappedInt.fetchCursor(db, Request(statement: { statement }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL UNION ALL SELECT 0, 'foo' UNION ALL SELECT 0, 2"
|
||||
@@ -176,13 +176,13 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(FastWrappedInt.fetchCursor(db, sql, adapter: adapter), sql: sql)
|
||||
try test(FastWrappedInt.fetchCursor(statement, adapter: adapter), sql: sql)
|
||||
try test(FastWrappedInt.fetchCursor(db, Request(statement: statement, adapter: adapter)), sql: sql)
|
||||
try test(FastWrappedInt.fetchCursor(db, Request(statement: { statement }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchCursorSQLiteFailure() {
|
||||
func testFetchCursorStepFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
@@ -213,14 +213,46 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT 1 UNION ALL SELECT throw() UNION ALL SELECT 2"
|
||||
try test(FastWrappedInt.fetchCursor(db, sql), sql: sql)
|
||||
try test(FastWrappedInt.fetchCursor(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(FastWrappedInt.fetchCursor(db, Request(statement: db.makeSelectStatement(sql), adapter: nil)), sql: sql)
|
||||
try test(FastWrappedInt.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, throw() UNION ALL SELECT 0, 2"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(FastWrappedInt.fetchCursor(db, sql, adapter: adapter), sql: sql)
|
||||
try test(FastWrappedInt.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(FastWrappedInt.fetchCursor(db, Request(statement: db.makeSelectStatement(sql), adapter: adapter)), sql: sql)
|
||||
try test(FastWrappedInt.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchCursorCompilationFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
func test(_ cursor: @autoclosure () throws -> DatabaseCursor<FastWrappedInt>, sql: String) throws {
|
||||
do {
|
||||
_ = try cursor()
|
||||
XCTFail()
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.code, 1) // SQLITE_ERROR
|
||||
XCTAssertEqual(error.message, "no such table: nonExistingTable")
|
||||
XCTAssertEqual(error.sql!, sql)
|
||||
XCTAssertEqual(error.description, "SQLite error 1 with statement `\(sql)`: no such table: nonExistingTable")
|
||||
}
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(FastWrappedInt.fetchCursor(db, sql), sql: sql)
|
||||
try test(FastWrappedInt.fetchCursor(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(FastWrappedInt.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(FastWrappedInt.fetchCursor(db, sql, adapter: adapter), sql: sql)
|
||||
try test(FastWrappedInt.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(FastWrappedInt.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,7 +271,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(FastWrappedInt.fetchAll(db, sql))
|
||||
try test(FastWrappedInt.fetchAll(statement))
|
||||
try test(FastWrappedInt.fetchAll(db, Request(statement: statement, adapter: nil)))
|
||||
try test(FastWrappedInt.fetchAll(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2"
|
||||
@@ -247,7 +279,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(FastWrappedInt.fetchAll(db, sql, adapter: adapter))
|
||||
try test(FastWrappedInt.fetchAll(statement, adapter: adapter))
|
||||
try test(FastWrappedInt.fetchAll(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(FastWrappedInt.fetchAll(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -273,7 +305,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(FastWrappedInt.fetchAll(db, sql), sql: sql)
|
||||
try test(FastWrappedInt.fetchAll(statement), sql: sql)
|
||||
try test(FastWrappedInt.fetchAll(db, Request(statement: statement, adapter: nil)), sql: sql)
|
||||
try test(FastWrappedInt.fetchAll(db, Request(statement: { statement }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL UNION ALL SELECT 0, 2"
|
||||
@@ -281,13 +313,13 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(FastWrappedInt.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(FastWrappedInt.fetchAll(statement, adapter: adapter), sql: sql)
|
||||
try test(FastWrappedInt.fetchAll(db, Request(statement: statement, adapter: adapter)), sql: sql)
|
||||
try test(FastWrappedInt.fetchAll(db, Request(statement: { statement }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchAllSQLiteFailure() {
|
||||
func testFetchAllStepFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
@@ -309,7 +341,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(FastWrappedInt.fetchAll(db, sql), sql: sql)
|
||||
try test(FastWrappedInt.fetchAll(statement), sql: sql)
|
||||
try test(FastWrappedInt.fetchAll(db, Request(statement: statement, adapter: nil)), sql: sql)
|
||||
try test(FastWrappedInt.fetchAll(db, Request(statement: { statement }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
@@ -317,7 +349,39 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(FastWrappedInt.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(FastWrappedInt.fetchAll(statement, adapter: adapter), sql: sql)
|
||||
try test(FastWrappedInt.fetchAll(db, Request(statement: statement, adapter: adapter)), sql: sql)
|
||||
try test(FastWrappedInt.fetchAll(db, Request(statement: { statement }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchAllCompilationFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
func test(_ array: @autoclosure () throws -> [FastWrappedInt], sql: String) throws {
|
||||
do {
|
||||
_ = try array()
|
||||
XCTFail()
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.code, 1) // SQLITE_ERROR
|
||||
XCTAssertEqual(error.message, "no such table: nonExistingTable")
|
||||
XCTAssertEqual(error.sql!, sql)
|
||||
XCTAssertEqual(error.description, "SQLite error 1 with statement `\(sql)`: no such table: nonExistingTable")
|
||||
}
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(FastWrappedInt.fetchAll(db, sql), sql: sql)
|
||||
try test(FastWrappedInt.fetchAll(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(FastWrappedInt.fetchAll(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(FastWrappedInt.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(FastWrappedInt.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(FastWrappedInt.fetchAll(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -336,7 +400,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(FastWrappedInt.fetchOne(db, sql))
|
||||
try test(FastWrappedInt.fetchOne(statement))
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: statement, adapter: nil)))
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 WHERE 0"
|
||||
@@ -344,7 +408,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(FastWrappedInt.fetchOne(db, sql, adapter: adapter))
|
||||
try test(FastWrappedInt.fetchOne(statement, adapter: adapter))
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
do {
|
||||
@@ -356,7 +420,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(FastWrappedInt.fetchOne(db, sql))
|
||||
try test(FastWrappedInt.fetchOne(statement))
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: statement, adapter: nil)))
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, NULL"
|
||||
@@ -364,7 +428,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(FastWrappedInt.fetchOne(db, sql, adapter: adapter))
|
||||
try test(FastWrappedInt.fetchOne(statement, adapter: adapter))
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
do {
|
||||
@@ -376,7 +440,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(FastWrappedInt.fetchOne(db, sql))
|
||||
try test(FastWrappedInt.fetchOne(statement))
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: statement, adapter: nil)))
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1"
|
||||
@@ -384,14 +448,14 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(FastWrappedInt.fetchOne(db, sql, adapter: adapter))
|
||||
try test(FastWrappedInt.fetchOne(statement, adapter: adapter))
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchOneSQLiteFailure() {
|
||||
func testFetchOneStepFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
@@ -413,7 +477,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(FastWrappedInt.fetchOne(db, sql), sql: sql)
|
||||
try test(FastWrappedInt.fetchOne(statement), sql: sql)
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: statement, adapter: nil)), sql: sql)
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: { statement }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
@@ -421,7 +485,39 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(FastWrappedInt.fetchOne(db, sql, adapter: adapter), sql: sql)
|
||||
try test(FastWrappedInt.fetchOne(statement, adapter: adapter), sql: sql)
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: statement, adapter: adapter)), sql: sql)
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: { statement }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchOneCompilationFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
func test(_ value: @autoclosure () throws -> FastWrappedInt?, sql: String) throws {
|
||||
do {
|
||||
_ = try value()
|
||||
XCTFail()
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.code, 1) // SQLITE_ERROR
|
||||
XCTAssertEqual(error.message, "no such table: nonExistingTable")
|
||||
XCTAssertEqual(error.sql!, sql)
|
||||
XCTAssertEqual(error.description, "SQLite error 1 with statement `\(sql)`: no such table: nonExistingTable")
|
||||
}
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(FastWrappedInt.fetchOne(db, sql), sql: sql)
|
||||
try test(FastWrappedInt.fetchOne(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(FastWrappedInt.fetchOne(db, sql, adapter: adapter), sql: sql)
|
||||
try test(FastWrappedInt.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(FastWrappedInt.fetchOne(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -445,7 +541,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db, sql))
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(statement))
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db, Request(statement: statement, adapter: nil)))
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL"
|
||||
@@ -453,7 +549,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db, sql, adapter: adapter))
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(statement, adapter: adapter))
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -488,7 +584,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db, sql), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(statement), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db, Request(statement: statement, adapter: nil)), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db, Request(statement: { statement }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL UNION ALL SELECT 0, 'foo' UNION ALL SELECT 0, 2"
|
||||
@@ -496,7 +592,39 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(statement, adapter: adapter), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db, Request(statement: statement, adapter: adapter)), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db, Request(statement: { statement }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testOptionalFetchCursorCompilationFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
func test(_ cursor: @autoclosure () throws -> DatabaseCursor<FastWrappedInt?>, sql: String) throws {
|
||||
do {
|
||||
_ = try cursor()
|
||||
XCTFail()
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.code, 1) // SQLITE_ERROR
|
||||
XCTAssertEqual(error.message, "no such table: nonExistingTable")
|
||||
XCTAssertEqual(error.sql!, sql)
|
||||
XCTAssertEqual(error.description, "SQLite error 1 with statement `\(sql)`: no such table: nonExistingTable")
|
||||
}
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db, sql), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchCursor(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -517,7 +645,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, sql))
|
||||
try test(Optional<FastWrappedInt>.fetchAll(statement))
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, Request(statement: statement, adapter: nil)))
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, Request(statement: { statement }, adapter: nil)))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL"
|
||||
@@ -525,7 +653,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, sql, adapter: adapter))
|
||||
try test(Optional<FastWrappedInt>.fetchAll(statement, adapter: adapter))
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, Request(statement: statement, adapter: adapter)))
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, Request(statement: { statement }, adapter: adapter)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -554,7 +682,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, sql), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(statement), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, Request(statement: statement, adapter: nil)), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, Request(statement: { statement }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL UNION ALL SELECT 0, 'foo' UNION ALL SELECT 0, 2"
|
||||
@@ -562,13 +690,13 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(statement, adapter: adapter), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, Request(statement: statement, adapter: adapter)), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, Request(statement: { statement }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testOptionalFetchAllSQLiteFailure() {
|
||||
func testOptionalFetchAllStepFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
@@ -590,7 +718,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, sql), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(statement), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, Request(statement: statement, adapter: nil)), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, Request(statement: { statement }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
@@ -598,7 +726,39 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(statement, adapter: adapter), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, Request(statement: statement, adapter: adapter)), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, Request(statement: { statement }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testOptionalFetchAllCompilationFailure() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
func test(_ array: @autoclosure () throws -> [FastWrappedInt?], sql: String) throws {
|
||||
do {
|
||||
_ = try array()
|
||||
XCTFail()
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.code, 1) // SQLITE_ERROR
|
||||
XCTAssertEqual(error.message, "no such table: nonExistingTable")
|
||||
XCTAssertEqual(error.sql!, sql)
|
||||
XCTAssertEqual(error.description, "SQLite error 1 with statement `\(sql)`: no such table: nonExistingTable")
|
||||
}
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, sql), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: nil)), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<FastWrappedInt>.fetchAll(db, Request(statement: { try db.makeSelectStatement(sql) }, adapter: adapter)), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user