]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java
add two indices, corresponding to foreign keys to help Room
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / utils / MobileLedgerDatabase.java
index 29d650a57ec7c46c7b8975900cda9f4faf64414f..eab4790205facea7c96534b40702b0d2bf3dbc67 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2020 Damyan Ivanov.
+ * Copyright © 2021 Damyan Ivanov.
  * This file is part of MoLe.
  * MoLe is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -24,6 +24,8 @@ import android.database.sqlite.SQLiteDatabase;
 import android.database.sqlite.SQLiteOpenHelper;
 import android.util.Log;
 
+import androidx.lifecycle.MutableLiveData;
+
 import net.ktnx.mobileledger.BuildConfig;
 
 import java.io.BufferedReader;
@@ -35,10 +37,10 @@ import java.util.Locale;
 import static net.ktnx.mobileledger.utils.Logger.debug;
 
 public class MobileLedgerDatabase extends SQLiteOpenHelper {
-    private static final String DB_NAME = "MoLe.db";
-    private static final int LATEST_REVISION = 40;
+    public static final MutableLiveData<Boolean> initComplete = new MutableLiveData<>(false);
+    public static final String DB_NAME = "MoLe.db";
+    private static final int LATEST_REVISION = 52;
     private static final String CREATE_DB_SQL = "create_db";
-
     private final Application mContext;
 
     public MobileLedgerDatabase(Application context) {
@@ -54,6 +56,13 @@ public class MobileLedgerDatabase extends SQLiteOpenHelper {
         applyRevisionFile(db, CREATE_DB_SQL);
     }
 
+    @Override
+    public void onConfigure(SQLiteDatabase db) {
+        super.onConfigure(db);
+        db.execSQL("pragma case_sensitive_like=ON;");
+        if (BuildConfig.DEBUG)
+            db.execSQL("PRAGMA foreign_keys=ON");
+    }
     @Override
     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
         debug("db",
@@ -62,14 +71,6 @@ public class MobileLedgerDatabase extends SQLiteOpenHelper {
         for (int i = oldVersion + 1; i <= newVersion; i++)
             applyRevision(db, i);
     }
-    @Override
-    public void onOpen(SQLiteDatabase db) {
-        super.onOpen(db);
-        db.execSQL("pragma case_sensitive_like=ON;");
-        if (BuildConfig.DEBUG)
-            db.execSQL("PRAGMA foreign_keys=ON");
-    }
-
     private void applyRevision(SQLiteDatabase db, int rev_no) {
         String rev_file = String.format(Locale.US, "sql_%d", rev_no);