@@ -78,6 +78,10 @@ JNIEXPORT jlong JNICALL Java_com_couchbase_lite_internal_database_sqlite_SQLiteC
7878 sqliteFlags = SQLITE_OPEN_READWRITE;
7979 }
8080
81+ // Serialized. In serialized mode, SQLite can be safely used by multiple threads with no restriction.
82+ // https://www.sqlite.org/threadsafe.html
83+ sqliteFlags |= SQLITE_OPEN_FULLMUTEX;
84+
8185 const char * pathCStr = env->GetStringUTFChars (pathStr, NULL );
8286 std::string path (pathCStr);
8387 env->ReleaseStringUTFChars (pathStr, pathCStr);
@@ -94,15 +98,12 @@ JNIEXPORT jlong JNICALL Java_com_couchbase_lite_internal_database_sqlite_SQLiteC
9498 return 0 ;
9599 }
96100
97- // Once Couchbase Lite change the supported Android API version to 16 or higher,
98- // we should remove following comment out.
99- // https://github.com/couchbase/couchbase-lite-android/issues/792
100101 // Check that the database is really read/write when that is what we asked for.
101- // if ((sqliteFlags & SQLITE_OPEN_READWRITE) && sqlite3_db_readonly(db, NULL)) {
102- // throw_sqlite3_exception(env, db, "Could not open the database in read/write mode.");
103- // sqlite3_close(db);
104- // return 0;
105- // }
102+ if ((sqliteFlags & SQLITE_OPEN_READWRITE) && sqlite3_db_readonly (db, NULL )) {
103+ throw_sqlite3_exception (env, db, " Could not open the database in read/write mode." );
104+ sqlite3_close (db);
105+ return 0 ;
106+ }
106107
107108 // Set the default busy handler to retry automatically before returning SQLITE_BUSY.
108109 err = sqlite3_busy_timeout (db, BUSY_TIMEOUT_MS);
0 commit comments