Search code examples
androidsqlitewal

How to enable Write-Ahead Log(WAL) journal mode for SQLite in android?


I want to enable WAL mode for journal_mode. I'm using the class SqliteDatabase of CIPHER package. It does not have a enableWriteAheadLogging() method. And instead of that I tried to enable the mode through transactions.

But there was an exception that "Caused by: net.sqlcipher.database.SQLiteException: cannot change into wal mode from within a transaction: PRAGMA journal_mode = WAL". I don't have no variants to solve it. Help me, please!


Solution

  • I was able to enable wal mode through SQLiteDatabaseHook::postKey while opening database. In the postKey() method need to execute database.rawExecSQL("PRAGMA journal_mode = WAL"); command.