diff --git a/GRDB/Core/Database+Schema.swift b/GRDB/Core/Database+Schema.swift index 2fcce080c..eb409a6b5 100644 --- a/GRDB/Core/Database+Schema.swift +++ b/GRDB/Core/Database+Schema.swift @@ -367,17 +367,9 @@ extension Database { } if (try? viewExists(tableName, in: schemaName)) == true { - if schemaSource == nil { - throw DatabaseError(message: """ - The database view '\(tableName)' has no primary key. \ - To support views, provide a custom schema source in Configuration.schemaSource. - """) - } else { - throw DatabaseError(message: """ - The database view '\(tableName)' has no primary key, \ - according to Configuration.schemaSource. - """) - } + throw DatabaseError(message: """ + database view \(tableName) has no primary key + """) } else { throw DatabaseError.noSuchTable(tableName) } @@ -404,18 +396,9 @@ extension Database { if case .SQLITE_ERROR = error.resultCode, (try? viewExists(tableName)) == true { - if schemaSource == nil { - fatalError(""" - Filtering by primary key is not available on the database view '\(tableName)'. \ - Instead, use `filter(Column("...") == value)`, or provide \ - a custom schema source in Configuration.schemaSource. - """) - } else { - fatalError(""" - Filtering by primary key requires a single-column primary key in the view '\(tableName)'. \ - No such primary key is configured by Configuration.schemaSource. - """) - } + throw DatabaseError(message: """ + database view \(tableName) has no primary key + """) } else { throw error } diff --git a/GRDB/Documentation.docc/ViewRecords.md b/GRDB/Documentation.docc/ViewRecords.md index 80cc0400f..5b256e264 100644 --- a/GRDB/Documentation.docc/ViewRecords.md +++ b/GRDB/Documentation.docc/ViewRecords.md @@ -14,7 +14,7 @@ let captains = try Captain.fetchAll(db) let captainCount = try Captain.fetchCount(db) // KO: Requires extra configuration -// SQLite error 1: The database view 'captain' has no primary key. +// SQLite error 1: database view captain has no primary key var bob = try Captain.find(db, id: "bob") bob.name = "Bobby" // SQLite error 1: cannot modify captain because it is a view diff --git a/GRDB/QueryInterface/Request/RequestProtocols.swift b/GRDB/QueryInterface/Request/RequestProtocols.swift index 924528135..e2b366d57 100644 --- a/GRDB/QueryInterface/Request/RequestProtocols.swift +++ b/GRDB/QueryInterface/Request/RequestProtocols.swift @@ -827,20 +827,10 @@ extension TableRequest where Self: FilteredRequest, Self: TypedRequest { // or unique index). guard let columns = try db.columnsForUniqueKey(key.keys, in: databaseTableName) else { if (try? db.viewExists(databaseTableName)) == true { - if db.schemaSource == nil { - fatalError(""" - view \(databaseTableName) has no unique key on column(s) \ - \(key.keys.sorted().joined(separator: ", ")). To support \ - keys in views, provide a custom schema source in \ - Configuration.schemaSource. - """) - } else { - fatalError(""" - view \(databaseTableName) has no unique key on column(s) \ - \(key.keys.sorted().joined(separator: ", ")), \ - according to Configuration.schemaSource. - """) - } + fatalError(""" + database view \(databaseTableName) has no unique key on column(s) \ + \(key.keys.sorted().joined(separator: ", ")) + """) } else { fatalError(""" table \(databaseTableName) has no unique key on column(s) \ diff --git a/Tests/GRDBTests/PrimaryKeyInfoTests.swift b/Tests/GRDBTests/PrimaryKeyInfoTests.swift index 25c9485ce..7cae11b84 100644 --- a/Tests/GRDBTests/PrimaryKeyInfoTests.swift +++ b/Tests/GRDBTests/PrimaryKeyInfoTests.swift @@ -27,14 +27,10 @@ class PrimaryKeyInfoTests: GRDBTestCase { } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) XCTAssertEqual(error.message, """ - The database view 'items' has no primary key. \ - To support views, provide a custom schema source \ - in Configuration.schemaSource. + database view items has no primary key """) XCTAssertEqual(error.description, """ - SQLite error 1: The database view 'items' has no primary key. \ - To support views, provide a custom schema source \ - in Configuration.schemaSource. + SQLite error 1: database view items has no primary key """) } } @@ -282,12 +278,10 @@ class PrimaryKeyInfoTests: GRDBTestCase { } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) XCTAssertEqual(error.message, """ - The database view 'playerView' has no primary key, \ - according to Configuration.schemaSource. + database view playerView has no primary key """) XCTAssertEqual(error.description, """ - SQLite error 1: The database view 'playerView' has no primary key, \ - according to Configuration.schemaSource. + SQLite error 1: database view playerView has no primary key """) } } @@ -322,12 +316,10 @@ class PrimaryKeyInfoTests: GRDBTestCase { } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_ERROR) XCTAssertEqual(error.message, """ - The database view 'playerView' has no primary key, \ - according to Configuration.schemaSource. + database view playerView has no primary key """) XCTAssertEqual(error.description, """ - SQLite error 1: The database view 'playerView' has no primary key, \ - according to Configuration.schemaSource. + SQLite error 1: database view playerView has no primary key """) } }