Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE to retry when SQLITE_OPEN_READWRITE fails on native platforms. #51

Merged
merged 9 commits into from
Oct 18, 2023
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
Loading