Skip to content

Commit 1d12b5c

Browse files
authored
Merge pull request #51 from migaku-official/main
use SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE to retry when SQLITE_OPEN_READWRITE fails on native platforms.
2 parents 0e5546d + 3013a60 commit 1d12b5c

File tree

1 file changed

+5
-0
lines changed
  • sqllin-driver/src/nativeMain/kotlin/com/ctrip/sqllin/driver/cinterop

1 file changed

+5
-0
lines changed

sqllin-driver/src/nativeMain/kotlin/com/ctrip/sqllin/driver/cinterop/NativeDatabase.kt

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ internal class NativeDatabase private constructor(val dbPointer: CPointer<sqlite
4949

5050
val db = memScoped {
5151
val dbPtr = alloc<CPointerVar<sqlite3>>()
52+
if(configuration.isReadOnly) {
53+
//from sqlite3_open_v2 docs: if opening in read-write mode fails due to OS-level permissions, an attempt is made to open it in read-only mode
54+
val openResult = sqlite3_open_v2(realPath, dbPtr.ptr, SQLITE_OPEN_READWRITE or SQLITE_OPEN_URI, null)
55+
if (openResult == SQLITE_OK) return@memScoped dbPtr.value!!
56+
}
5257
val openResult = sqlite3_open_v2(realPath, dbPtr.ptr, sqliteFlags, null)
5358
if (openResult != SQLITE_OK) {
5459
throw sqliteException(sqlite3_errmsg(dbPtr.value)?.toKString() ?: "", openResult)

0 commit comments

Comments
 (0)