]> git.ktnx.net Git - mobile-ledger-staging.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java
UI and machinery for detecting hledger-web version
[mobile-ledger-staging.git] / app / src / main / java / net / ktnx / mobileledger / utils / MobileLedgerDatabase.java
index fc03a9f8cfc5431ee7ebfd2fc0b841bc0a78b74b..8f8be513c8e60a837bcedca09fe02fc288c527c6 100644 (file)
@@ -24,6 +24,10 @@ 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;
 import java.io.IOException;
 import java.io.InputStream;
@@ -33,10 +37,10 @@ import java.util.Locale;
 import static net.ktnx.mobileledger.utils.Logger.debug;
 
 public class MobileLedgerDatabase extends SQLiteOpenHelper {
+    public static final MutableLiveData<Boolean> initComplete = new MutableLiveData<>(false);
     private static final String DB_NAME = "MoLe.db";
-    private static final int LATEST_REVISION = 37;
+    private static final int LATEST_REVISION = 41;
     private static final String CREATE_DB_SQL = "create_db";
-
     private final Application mContext;
 
     public MobileLedgerDatabase(Application context) {
@@ -52,19 +56,21 @@ 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", "onUpgrade called");
+        debug("db",
+                String.format(Locale.US, "needs upgrade from version %d to version %d", oldVersion,
+                        newVersion));
         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;");
-//        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);