I'm trying to create a backup of my apps database contents and for most devices it works fine but a few have wal mode enabled by default which causes an issue. From everything I've read calling "pragma wal_checkpoint" should flush the contents of a -wal file into the main database file which is what I'm after. Flush the contents to main db file and then copy the db file for backup. I'm calling
db.rawQuery("pragma wal_checkpoint;", null);
but it doesn't seem to be working. Any ideas?
rawQuery() returns a cursor; the query is not actually executed until you try to read from the cursor.
To execute an SQL statement that does not return a cursor, use execSQL() instead.
It's worked for me to flush wal file to main database.
String query = "pragma wal_checkpoint(full)";
Cursor cursor = db.rawQuery(query, null);
if (cursor != null && cursor.moveToFirst()) {
int a = cursor.getInt(0);
int b = cursor.getInt(1);
int c = cursor.getInt(2);
}
if (cursor != null) {
cursor.close();
}
db.close();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With