From 9b61405891986bf0faa949cc4dbd014dfbd03850 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 24 Aug 2018 12:31:51 +0000 Subject: [PATCH] Removed sqlite workaround because there were side effects --- app/src/main/java/eu/faircode/email/DB.java | 36 ++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DB.java b/app/src/main/java/eu/faircode/email/DB.java index c809f6cf..05372c54 100644 --- a/app/src/main/java/eu/faircode/email/DB.java +++ b/app/src/main/java/eu/faircode/email/DB.java @@ -75,20 +75,31 @@ public abstract class DB extends RoomDatabase { private static final String DB_NAME = "email"; public static synchronized DB getInstance(Context context) { - if (sInstance == null) + if (sInstance == null) { sInstance = migrate(Room .databaseBuilder(context.getApplicationContext(), DB.class, DB_NAME) .setJournalMode(JournalMode.WRITE_AHEAD_LOGGING)); + Log.i(Helper.TAG, "sqlite version=" + exec(sInstance, "SELECT sqlite_version() AS sqlite_version")); + Log.i(Helper.TAG, "sqlite sync=" + exec(sInstance, "PRAGMA synchronous")); + Log.i(Helper.TAG, "sqlite journal=" + exec(sInstance, "PRAGMA journal_mode")); + } + return sInstance; } - @Override - public void beginTransaction() { - // This is a workaround for sqlite crashing on some devices - // Confusingly, the journal mode needs to be set to write ahead logging first for this to work - getOpenHelper().setWriteAheadLoggingEnabled(false); - super.beginTransaction(); + static String exec(DB db, String command) { + Cursor cursor = null; + try { + cursor = db.query(command, new Object[0]); + if (cursor.moveToNext()) + return cursor.getString(0); + else + return null; + } finally { + if (cursor != null) + cursor.close(); + } } private static DB migrate(RoomDatabase.Builder builder) { @@ -97,17 +108,6 @@ public abstract class DB extends RoomDatabase { @Override public void onOpen(SupportSQLiteDatabase db) { Log.i(Helper.TAG, "Database version=" + db.getVersion()); - - Cursor cursor = null; - try { - cursor = db.query("SELECT sqlite_version() AS sqlite_version"); - if (cursor.moveToNext()) - Log.i(Helper.TAG, "sqlite version=" + cursor.getString(0)); - } finally { - if (cursor != null) - cursor.close(); - } - super.onOpen(db); } })