Removed sqlite workaround because there were side effects

pull/31/merge
M66B 6 years ago
parent 29fbf06c4b
commit 9b61405891

@ -75,39 +75,39 @@ 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));
return sInstance;
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"));
}
@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();
return sInstance;
}
private static DB migrate(RoomDatabase.Builder<DB> builder) {
return builder
.addCallback(new Callback() {
@Override
public void onOpen(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "Database version=" + db.getVersion());
static String exec(DB db, String command) {
Cursor cursor = null;
try {
cursor = db.query("SELECT sqlite_version() AS sqlite_version");
cursor = db.query(command, new Object[0]);
if (cursor.moveToNext())
Log.i(Helper.TAG, "sqlite version=" + cursor.getString(0));
return cursor.getString(0);
else
return null;
} finally {
if (cursor != null)
cursor.close();
}
}
private static DB migrate(RoomDatabase.Builder<DB> builder) {
return builder
.addCallback(new Callback() {
@Override
public void onOpen(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "Database version=" + db.getVersion());
super.onOpen(db);
}
})

Loading…
Cancel
Save