FTS5.api(_:) can now throw an error

This commit is contained in:
Gwendal Roué committed 2017-07-21 18:34:19 +02:00
1 parent 7b2e672496
commit bb931e9da7
3 files changed
+7 -14

No files matched your search

+4 -7
View File
@@ -132,14 +132,11 @@
}
}
static func api(_ db: Database) -> UnsafePointer<fts5_api>? {
do {
return try Data
.fetchOne(db, "SELECT fts5()")
.flatMap { $0.withUnsafeBytes { $0.pointee } }
} catch {
return nil
static func api(_ db: Database) throws -> UnsafePointer<fts5_api> {
guard let data = try Data.fetchOne(db, "SELECT fts5()") else {
throw DatabaseError(message: "FTS5 is not available")
}
return data.withUnsafeBytes { $0.pointee }
}
}
+2 -4
View File
@@ -55,10 +55,8 @@
/// class MyTokenizer : FTS5CustomTokenizer { ... }
/// db.add(tokenizer: MyTokenizer.self)
public func add<Tokenizer: FTS5CustomTokenizer>(tokenizer: Tokenizer.Type) {
guard let api = FTS5.api(self) else {
// Assume a GRDB bug or an SQLite miscompilation: there is no point throwing any error.
fatalError("FTS5 is not enabled")
}
// TODO GRDB 2.0: let this method throw when FTS5 can't be loaded
let api = try! FTS5.api(self)
// Swift won't let the @convention(c) xCreate() function below create
// an instance of the generic Tokenizer type.
+1 -3
View File
@@ -188,9 +188,7 @@
/// }
/// }
public func makeTokenizer(_ descriptor: FTS5TokenizerDescriptor) throws -> FTS5Tokenizer {
guard let api = FTS5.api(self) else {
throw DatabaseError(resultCode: .SQLITE_MISUSE, message: "FTS5 API not found")
}
let api = try FTS5.api(self)
let xTokenizerPointer: UnsafeMutablePointer<fts5_tokenizer> = .allocate(capacity: 1)
defer { xTokenizerPointer.deallocate(capacity: 1) }