mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Disable write-ahead log on SQLite
Android 9 (Pie) silently introduced a new behavior where new SQLite databases have Write-Ahead Logs (WALs) enabled by default. The data, even after committed, is not written to the main database file until later. This caused a silent bug leading to data loss, where exported backups would either be empty or miss some recent data.
This commit is contained in:
@@ -34,13 +34,20 @@ class HabitsDatabaseOpener(
|
||||
) : SQLiteOpenHelper(context, databaseFilename, null, version) {
|
||||
|
||||
override fun onCreate(db: SQLiteDatabase) {
|
||||
db.disableWriteAheadLogging()
|
||||
db.version = 8
|
||||
onUpgrade(db, -1, version)
|
||||
}
|
||||
|
||||
override fun onOpen(db: SQLiteDatabase) {
|
||||
super.onOpen(db)
|
||||
db.disableWriteAheadLogging()
|
||||
}
|
||||
|
||||
override fun onUpgrade(db: SQLiteDatabase,
|
||||
oldVersion: Int,
|
||||
newVersion: Int) {
|
||||
db.disableWriteAheadLogging()
|
||||
if (db.version < 8) throw UnsupportedDatabaseVersionException()
|
||||
val helper = MigrationHelper(AndroidDatabase(db))
|
||||
helper.migrateTo(newVersion)
|
||||
|
||||
@@ -66,7 +66,7 @@ public class ExportDBTask implements Task
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user