mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Database.primaryKey() fails for views
This commit is contained in:
1 parent
340203686d
commit
dcc2d211b2
2 files changed
+35
No files matched your search
@@ -199,6 +199,12 @@ extension Database {
|
||||
return primaryKey.value
|
||||
}
|
||||
|
||||
if try !tableExists(table) {
|
||||
// Views, CTEs, etc.
|
||||
schemaCache[table.schemaID].set(primaryKey: .missing, forTable: table.name)
|
||||
return nil
|
||||
}
|
||||
|
||||
// https://www.sqlite.org/pragma.html
|
||||
//
|
||||
// > PRAGMA database.table_info(table-name);
|
||||
|
||||
@@ -3,6 +3,35 @@ import XCTest
|
||||
|
||||
class PrimaryKeyInfoTests: GRDBTestCase {
|
||||
|
||||
func testMissingTable() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
_ = try db.primaryKey("items")
|
||||
XCTFail("Expected Error")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
XCTAssertEqual(error.message, "no such table: items")
|
||||
XCTAssertEqual(error.description, "SQLite error 1: no such table: items")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testView() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(sql: "CREATE VIEW items AS SELECT 1")
|
||||
do {
|
||||
_ = try db.primaryKey("items")
|
||||
XCTFail("Expected Error")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
XCTAssertEqual(error.message, "no such table: items")
|
||||
XCTAssertEqual(error.description, "SQLite error 1: no such table: items")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testHiddenRowID() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
|
||||
Reference in new issue
Block a user