Skip to content

Commit f2859ff

Browse files
committed
Use SQLITE_OPEN_EXRESCODE when available
1 parent e2b412a commit f2859ff

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

GRDB/Core/Configuration.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,11 @@ public struct Configuration {
296296
var SQLiteConnectionWillClose: ((SQLiteConnection) -> Void)?
297297
var SQLiteConnectionDidClose: (() -> Void)?
298298
var SQLiteOpenFlags: CInt {
299-
let readWriteFlags = readonly ? SQLITE_OPEN_READONLY : (SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE)
300-
return threadingMode.SQLiteOpenFlags | readWriteFlags
299+
var flags = readonly ? SQLITE_OPEN_READONLY : (SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE)
300+
if sqlite3_libversion_number() >= 3037000 {
301+
flags |= 0x02000000 // SQLITE_OPEN_EXRESCODE
302+
}
303+
return threadingMode.SQLiteOpenFlags | flags
301304
}
302305

303306
func setUp(_ db: Database) throws {

GRDB/Core/Database.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
347347
}
348348

349349
private func activateExtendedCodes() throws {
350+
if (configuration.SQLiteOpenFlags & 0x02000000 /* SQLITE_OPEN_EXRESCODE */) != 0 {
351+
// Nothing to do
352+
return
353+
}
350354
let code = sqlite3_extended_result_codes(sqliteConnection, 1)
351355
guard code == SQLITE_OK else {
352356
throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection)))

0 commit comments

Comments
 (0)