Use SQLITE_OPEN_EXRESCODE when available

This commit is contained in:
Gwendal Roué committed 2022-08-28 12:50:47 +02:00
1 parent e2b412afc8
commit f2859ff8bf
2 files changed
+9 -2

No files matched your search

+5 -2
View File
@@ -296,8 +296,11 @@ public struct Configuration {
var SQLiteConnectionWillClose: ((SQLiteConnection) -> Void)?
var SQLiteConnectionDidClose: (() -> Void)?
var SQLiteOpenFlags: CInt {
let readWriteFlags = readonly ? SQLITE_OPEN_READONLY : (SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE)
return threadingMode.SQLiteOpenFlags | readWriteFlags
var flags = readonly ? SQLITE_OPEN_READONLY : (SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE)
if sqlite3_libversion_number() >= 3037000 {
flags |= 0x02000000 // SQLITE_OPEN_EXRESCODE
}
return threadingMode.SQLiteOpenFlags | flags
}
func setUp(_ db: Database) throws {
+4
View File
@@ -347,6 +347,10 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
}
private func activateExtendedCodes() throws {
if (configuration.SQLiteOpenFlags & 0x02000000 /* SQLITE_OPEN_EXRESCODE */) != 0 {
// Nothing to do
return
}
let code = sqlite3_extended_result_codes(sqliteConnection, 1)
guard code == SQLITE_OK else {
throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection)))