mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Test strict tables, and table/index creation options
This commit is contained in:
1 parent
8760033045
commit
68f3e5586b
1 file changed
+44
-1
@@ -33,6 +33,46 @@ class TableDefinitionTests: GRDBTestCase {
|
||||
) WITHOUT ROWID
|
||||
""")
|
||||
}
|
||||
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(table: "test2", options: [.temporary, .ifNotExists, .withoutRowID]) { t in
|
||||
t.column("id", .integer).primaryKey()
|
||||
}
|
||||
assertEqualSQL(lastSQLQuery!, """
|
||||
CREATE TEMPORARY TABLE IF NOT EXISTS "test2" (\
|
||||
"id" INTEGER PRIMARY KEY\
|
||||
) WITHOUT ROWID
|
||||
""")
|
||||
}
|
||||
|
||||
#if GRDBCUSTOMSQLITE
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(table: "test3", options: [.strict, .withoutRowID]) { t in
|
||||
t.column("id", .integer).primaryKey()
|
||||
t.column("a", .integer)
|
||||
t.column("b", .real)
|
||||
t.column("c", .text)
|
||||
t.column("d", .blob)
|
||||
t.column("e", .any)
|
||||
}
|
||||
assertEqualSQL(lastSQLQuery!, """
|
||||
CREATE TABLE "test3" (\
|
||||
"id" INTEGER PRIMARY KEY, \
|
||||
"a" INTEGER, \
|
||||
"b" REAL, \
|
||||
"c" TEXT, \
|
||||
"d" BLOB, \
|
||||
"e" ANY\
|
||||
) STRICT, WITHOUT ROWID
|
||||
""")
|
||||
|
||||
do {
|
||||
try db.execute(sql: "INSERT INTO test3 (id, a) VALUES (1, 'foo')")
|
||||
XCTFail("Expected DatabaseError.SQLITE_CONSTRAINT_DATATYPE")
|
||||
} catch DatabaseError.SQLITE_CONSTRAINT_DATATYPE {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
func testColumnLiteral() throws {
|
||||
@@ -663,8 +703,11 @@ class TableDefinitionTests: GRDBTestCase {
|
||||
try db.create(index: "test_on_a_b", on: "test", columns: ["a", "b"], unique: true, ifNotExists: true)
|
||||
assertEqualSQL(lastSQLQuery!, "CREATE UNIQUE INDEX IF NOT EXISTS \"test_on_a_b\" ON \"test\"(\"a\", \"b\")")
|
||||
|
||||
try db.create(index: "test_on_a_b_2", on: "test", columns: ["a", "b"], options: [.unique, .ifNotExists])
|
||||
assertEqualSQL(lastSQLQuery!, "CREATE UNIQUE INDEX IF NOT EXISTS \"test_on_a_b_2\" ON \"test\"(\"a\", \"b\")")
|
||||
|
||||
// Sanity check
|
||||
XCTAssertEqual(try Set(db.indexes(on: "test").map(\.name)), ["test_on_a", "test_on_a_b"])
|
||||
XCTAssertEqual(try Set(db.indexes(on: "test").map(\.name)), ["test_on_a", "test_on_a_b", "test_on_a_b_2"])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user