Skip to content

Commit

Permalink
Merge pull request #51 from migaku-official/main
Browse files Browse the repository at this point in the history
use SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE to retry when SQLITE_OPEN_READWRITE fails on native platforms.
  • Loading branch information
qiaoyuang authored Oct 18, 2023
2 parents 0e5546d + 3013a60 commit 1d12b5c
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ internal class NativeDatabase private constructor(val dbPointer: CPointer<sqlite

val db = memScoped {
val dbPtr = alloc<CPointerVar<sqlite3>>()
if(configuration.isReadOnly) {
//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
val openResult = sqlite3_open_v2(realPath, dbPtr.ptr, SQLITE_OPEN_READWRITE or SQLITE_OPEN_URI, null)
if (openResult == SQLITE_OK) return@memScoped dbPtr.value!!
}
val openResult = sqlite3_open_v2(realPath, dbPtr.ptr, sqliteFlags, null)
if (openResult != SQLITE_OK) {
throw sqliteException(sqlite3_errmsg(dbPtr.value)?.toKString() ?: "", openResult)
Expand Down

0 comments on commit 1d12b5c

Please sign in to comment.