diff --git a/sqllin-driver/src/nativeMain/kotlin/com/ctrip/sqllin/driver/cinterop/NativeDatabase.kt b/sqllin-driver/src/nativeMain/kotlin/com/ctrip/sqllin/driver/cinterop/NativeDatabase.kt index 1fa92d0..9f18baa 100644 --- a/sqllin-driver/src/nativeMain/kotlin/com/ctrip/sqllin/driver/cinterop/NativeDatabase.kt +++ b/sqllin-driver/src/nativeMain/kotlin/com/ctrip/sqllin/driver/cinterop/NativeDatabase.kt @@ -49,6 +49,11 @@ internal class NativeDatabase private constructor(val dbPointer: CPointer>() + 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)