mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
Tests for StatementColumnConvertible fetching methods with adapter
This commit is contained in:
1 parent
21e9e64b3d
commit
aaf184ddb3
1 file changed
+214
-17
+214
-17
@@ -93,7 +93,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (2)")
|
||||
|
||||
let statement = try db.selectStatement("SELECT int FROM ints ORDER BY int")
|
||||
let statement = try db.selectStatement("SELECT int, -int FROM ints ORDER BY int")
|
||||
let sequence = FastWrappedInt.fetch(statement)
|
||||
|
||||
XCTAssertEqual(Array(sequence).map { $0.int }, [1,2])
|
||||
@@ -102,6 +102,24 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchFromStatementWithAdapter() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE ints (int Int)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (2)")
|
||||
|
||||
let statement = try db.selectStatement("SELECT int, -int FROM ints ORDER BY int")
|
||||
let sequence = FastWrappedInt.fetch(statement, adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
|
||||
XCTAssertEqual(Array(sequence).map { $0.int }, [-1,-2])
|
||||
// NICE TO HAVE: make it fast, and the following test pass:
|
||||
// XCTAssertEqual(Array(sequence).map { $0.fast }, [true, true])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchAllFromStatement() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
@@ -110,7 +128,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (2)")
|
||||
|
||||
let statement = try db.selectStatement("SELECT int FROM ints ORDER BY int")
|
||||
let statement = try db.selectStatement("SELECT int, -int FROM ints ORDER BY int")
|
||||
let array = FastWrappedInt.fetchAll(statement)
|
||||
|
||||
XCTAssertEqual(array.map { $0.int }, [1,2])
|
||||
@@ -119,12 +137,30 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchAllFromStatementWithAdapter() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE ints (int Int)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (2)")
|
||||
|
||||
let statement = try db.selectStatement("SELECT int, -int FROM ints ORDER BY int")
|
||||
let array = FastWrappedInt.fetchAll(statement, adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
|
||||
XCTAssertEqual(array.map { $0.int }, [-1,-2])
|
||||
// NICE TO HAVE: make it fast, and the following test pass:
|
||||
// XCTAssertEqual(array.map { $0.fast }, [true, true])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchOneFromStatement() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE ints (int Int)")
|
||||
let statement = try db.selectStatement("SELECT int FROM ints ORDER BY int")
|
||||
let statement = try db.selectStatement("SELECT int, -int FROM ints ORDER BY int")
|
||||
|
||||
let nilBecauseMissingRow = FastWrappedInt.fetchOne(statement)
|
||||
XCTAssertTrue(nilBecauseMissingRow == nil)
|
||||
@@ -142,7 +178,31 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchFromDatabase() {
|
||||
func testFetchOneFromStatementWithAdapter() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE ints (int Int)")
|
||||
let statement = try db.selectStatement("SELECT int, -int FROM ints ORDER BY int")
|
||||
|
||||
let nilBecauseMissingRow = FastWrappedInt.fetchOne(statement, adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
XCTAssertTrue(nilBecauseMissingRow == nil)
|
||||
|
||||
try db.execute("INSERT INTO ints (int) VALUES (NULL)")
|
||||
let nilBecauseMissingNULL = FastWrappedInt.fetchOne(statement, adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
XCTAssertTrue(nilBecauseMissingNULL == nil)
|
||||
|
||||
try db.execute("DELETE FROM ints")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
let one = FastWrappedInt.fetchOne(statement, adapter: SuffixRowAdapter(fromIndex: 1))!
|
||||
XCTAssertEqual(one.int, -1)
|
||||
// NICE TO HAVE: make it fast, and the following test pass:
|
||||
// XCTAssertEqual(one.fast, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchFromSQL() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
@@ -150,7 +210,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (2)")
|
||||
|
||||
let sequence = FastWrappedInt.fetch(db, "SELECT int FROM ints ORDER BY int")
|
||||
let sequence = FastWrappedInt.fetch(db, "SELECT int, -int FROM ints ORDER BY int")
|
||||
|
||||
XCTAssertEqual(Array(sequence).map { $0.int }, [1,2])
|
||||
XCTAssertEqual(Array(sequence).map { $0.fast }, [true, true])
|
||||
@@ -158,7 +218,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchAllFromDatabase() {
|
||||
func testFetchFromSQLWithAdapter() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
@@ -166,7 +226,24 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (2)")
|
||||
|
||||
let array = FastWrappedInt.fetchAll(db, "SELECT int FROM ints ORDER BY int")
|
||||
let sequence = FastWrappedInt.fetch(db, "SELECT int, -int FROM ints ORDER BY int", adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
|
||||
XCTAssertEqual(Array(sequence).map { $0.int }, [-1,-2])
|
||||
// NICE TO HAVE: make it fast, and the following test pass:
|
||||
// XCTAssertEqual(Array(sequence).map { $0.fast }, [true, true])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchAllFromSQL() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE ints (int Int)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (2)")
|
||||
|
||||
let array = FastWrappedInt.fetchAll(db, "SELECT int, -int FROM ints ORDER BY int")
|
||||
|
||||
XCTAssertEqual(array.map { $0.int }, [1,2])
|
||||
XCTAssertEqual(array.map { $0.fast }, [true, true])
|
||||
@@ -174,28 +251,68 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchOneFromDatabase() {
|
||||
func testFetchAllFromSQLWithAdapter() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE ints (int Int)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (2)")
|
||||
|
||||
let array = FastWrappedInt.fetchAll(db, "SELECT int, -int FROM ints ORDER BY int", adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
|
||||
XCTAssertEqual(array.map { $0.int }, [-1,-2])
|
||||
// NICE TO HAVE: make it fast, and the following test pass:
|
||||
// XCTAssertEqual(array.map { $0.fast }, [true, true])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchOneFromSQL() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE ints (int Int)")
|
||||
|
||||
let nilBecauseMissingRow = FastWrappedInt.fetchOne(db, "SELECT int FROM ints ORDER BY int")
|
||||
let nilBecauseMissingRow = FastWrappedInt.fetchOne(db, "SELECT int, -int FROM ints ORDER BY int")
|
||||
XCTAssertTrue(nilBecauseMissingRow == nil)
|
||||
|
||||
try db.execute("INSERT INTO ints (int) VALUES (NULL)")
|
||||
let nilBecauseMissingNULL = FastWrappedInt.fetchOne(db, "SELECT int FROM ints ORDER BY int")
|
||||
let nilBecauseMissingNULL = FastWrappedInt.fetchOne(db, "SELECT int, -int FROM ints ORDER BY int")
|
||||
XCTAssertTrue(nilBecauseMissingNULL == nil)
|
||||
|
||||
try db.execute("DELETE FROM ints")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
let one = FastWrappedInt.fetchOne(db, "SELECT int FROM ints ORDER BY int")!
|
||||
let one = FastWrappedInt.fetchOne(db, "SELECT int, -int FROM ints ORDER BY int")!
|
||||
XCTAssertEqual(one.int, 1)
|
||||
XCTAssertEqual(one.fast, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFetchOneFromSQLWithAdapter() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE ints (int Int)")
|
||||
|
||||
let nilBecauseMissingRow = FastWrappedInt.fetchOne(db, "SELECT int, -int FROM ints ORDER BY int", adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
XCTAssertTrue(nilBecauseMissingRow == nil)
|
||||
|
||||
try db.execute("INSERT INTO ints (int) VALUES (NULL)")
|
||||
let nilBecauseMissingNULL = FastWrappedInt.fetchOne(db, "SELECT int, -int FROM ints ORDER BY int", adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
XCTAssertTrue(nilBecauseMissingNULL == nil)
|
||||
|
||||
try db.execute("DELETE FROM ints")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
let one = FastWrappedInt.fetchOne(db, "SELECT int, -int FROM ints ORDER BY int", adapter: SuffixRowAdapter(fromIndex: 1))!
|
||||
XCTAssertEqual(one.int, -1)
|
||||
// NICE TO HAVE: make it fast, and the following test pass:
|
||||
// XCTAssertEqual(one.fast, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testOptionalFetchFromStatement() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
@@ -204,7 +321,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (NULL)")
|
||||
|
||||
let statement = try db.selectStatement("SELECT int FROM ints ORDER BY int")
|
||||
let statement = try db.selectStatement("SELECT int, -int FROM ints ORDER BY int")
|
||||
let sequence = Optional<FastWrappedInt>.fetch(statement)
|
||||
|
||||
let ints = Array(sequence)
|
||||
@@ -217,6 +334,27 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testOptionalFetchFromStatementWithAdapter() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE ints (int Int)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (NULL)")
|
||||
|
||||
let statement = try db.selectStatement("SELECT int, -int FROM ints ORDER BY int")
|
||||
let sequence = Optional<FastWrappedInt>.fetch(statement, adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
|
||||
let ints = Array(sequence)
|
||||
XCTAssertEqual(ints.count, 2)
|
||||
XCTAssertTrue(ints[0] == nil)
|
||||
XCTAssertEqual(ints[1]!.int, -1)
|
||||
// TODO: uncomment when we have a workaround for rdar://22852669
|
||||
// XCTAssertEqual(ints[1]!.fast, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testOptionalFetchAllFromStatement() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
@@ -225,7 +363,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (NULL)")
|
||||
|
||||
let statement = try db.selectStatement("SELECT int FROM ints ORDER BY int")
|
||||
let statement = try db.selectStatement("SELECT int, -int FROM ints ORDER BY int")
|
||||
let array = Optional<FastWrappedInt>.fetchAll(statement)
|
||||
|
||||
XCTAssertEqual(array.count, 2)
|
||||
@@ -237,7 +375,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testOptionalFetchFromDatabase() {
|
||||
func testOptionalFetchAllFromStatementWithAdapter() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
@@ -245,7 +383,27 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (NULL)")
|
||||
|
||||
let sequence = Optional<FastWrappedInt>.fetch(db, "SELECT int FROM ints ORDER BY int")
|
||||
let statement = try db.selectStatement("SELECT int, -int FROM ints ORDER BY int")
|
||||
let array = Optional<FastWrappedInt>.fetchAll(statement, adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
|
||||
XCTAssertEqual(array.count, 2)
|
||||
XCTAssertTrue(array[0] == nil)
|
||||
XCTAssertEqual(array[1]!.int, -1)
|
||||
// TODO: uncomment when we have a workaround for rdar://22852669
|
||||
// XCTAssertEqual(array[1]!.fast, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testOptionalFetchFromSQL() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE ints (int Int)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (NULL)")
|
||||
|
||||
let sequence = Optional<FastWrappedInt>.fetch(db, "SELECT int, -int FROM ints ORDER BY int")
|
||||
|
||||
let ints = Array(sequence)
|
||||
XCTAssertEqual(ints.count, 2)
|
||||
@@ -257,7 +415,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testOptionalFetchAllFromDatabase() {
|
||||
func testOptionalFetchFromSQLWithAdapter() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
@@ -265,12 +423,51 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (NULL)")
|
||||
|
||||
let array = Optional<FastWrappedInt>.fetchAll(db, "SELECT int FROM ints ORDER BY int")
|
||||
let sequence = Optional<FastWrappedInt>.fetch(db, "SELECT int, -int FROM ints ORDER BY int", adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
|
||||
let ints = Array(sequence)
|
||||
XCTAssertEqual(ints.count, 2)
|
||||
XCTAssertTrue(ints[0] == nil)
|
||||
XCTAssertEqual(ints[1]!.int, -1)
|
||||
// TODO: uncomment when we have a workaround for rdar://22852669
|
||||
// XCTAssertEqual(ints[1]!.fast, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testOptionalFetchAllFromSQL() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE ints (int Int)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (NULL)")
|
||||
|
||||
let array = Optional<FastWrappedInt>.fetchAll(db, "SELECT int, -int FROM ints ORDER BY int")
|
||||
|
||||
XCTAssertEqual(array.count, 2)
|
||||
XCTAssertTrue(array[0] == nil)
|
||||
XCTAssertEqual(array[1]!.int, 1)
|
||||
// TODO: uncomment when we have a workaround for rdar://22852669
|
||||
// XCTAssertEqual(array[1]!.fast, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testOptionalFetchAllFromSQLWithAdapter() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE ints (int Int)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute("INSERT INTO ints (int) VALUES (NULL)")
|
||||
|
||||
let array = Optional<FastWrappedInt>.fetchAll(db, "SELECT int, -int FROM ints ORDER BY int", adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
|
||||
XCTAssertEqual(array.count, 2)
|
||||
XCTAssertTrue(array[0] == nil)
|
||||
XCTAssertEqual(array[1]!.int, -1)
|
||||
// TODO: uncomment when we have a workaround for rdar://22852669
|
||||
// XCTAssertEqual(array[1]!.fast, true)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user