mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-22 04:00:39 +00:00
Failing test for the column cache of a recompiled statement
This commit is contained in:
1 parent
6f64c72209
commit
94fa864eb7
1 file changed
+22
@@ -388,4 +388,26 @@ class SelectStatementTests : GRDBTestCase {
|
||||
XCTAssertEqual(observers.map(\.triggered), [true, true, true, true])
|
||||
}
|
||||
}
|
||||
|
||||
func testColumnsAfterSchemaChange() throws {
|
||||
// SQLite recompiles statements after a schema change, and this can
|
||||
// change the result columns.
|
||||
try makeDatabaseQueue().inDatabase { db in
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE t(a);
|
||||
INSERT INTO t VALUES (1);
|
||||
""")
|
||||
let statement = try db.makeStatement(sql: "SELECT * FROM t")
|
||||
XCTAssertEqual(statement.columnNames, ["a"])
|
||||
XCTAssertEqual(statement.index(ofColumn: "a"), 0)
|
||||
XCTAssertNil(statement.index(ofColumn: "b"))
|
||||
|
||||
try db.execute(sql: "ALTER TABLE t ADD COLUMN b")
|
||||
try statement.execute() // Recompile
|
||||
XCTAssertEqual(statement.columnCount, 2)
|
||||
XCTAssertEqual(statement.columnNames, ["a", "b"])
|
||||
XCTAssertEqual(statement.index(ofColumn: "a"), 0)
|
||||
XCTAssertEqual(statement.index(ofColumn: "b"), 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user