]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java
initialize Room after all legacy upgrading is done
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / utils / MobileLedgerDatabase.java
index 96f022b4ace6322765bb81acce5e83fa34e62a24..78c325e1317ef7673fcd6e20119ec3254eb2e98e 100644 (file)
@@ -26,6 +26,7 @@ import android.database.sqlite.SQLiteOpenHelper;
 import androidx.lifecycle.MutableLiveData;
 
 import net.ktnx.mobileledger.BuildConfig;
+import net.ktnx.mobileledger.db.DB;
 
 import java.io.BufferedReader;
 import java.io.IOException;
@@ -40,10 +41,17 @@ import static net.ktnx.mobileledger.utils.Logger.debug;
 public class MobileLedgerDatabase extends SQLiteOpenHelper {
     public static final MutableLiveData<Boolean> initComplete = new MutableLiveData<>(false);
     public static final String DB_NAME = "MoLe.db";
-    private static final int LATEST_REVISION = 57;
+    private static final int LATEST_REVISION = 58;
     private static final String CREATE_DB_SQL = "create_db";
     private final Application mContext;
-
+    @Override
+    public void onOpen(SQLiteDatabase db) {
+        super.onOpen(db);
+        // force a check by Room to ensure everything is OK
+        // TODO: remove when all DB structure manipulation is via Room
+        DB.get()
+          .compileStatement("SELECT COUNT(*) FROM profiles");
+    }
     public MobileLedgerDatabase(Application context) {
         super(context, DB_NAME, null, LATEST_REVISION);
         debug("db", "creating helper instance");
@@ -88,7 +96,7 @@ public class MobileLedgerDatabase extends SQLiteOpenHelper {
             InputStreamReader isr = new InputStreamReader(res);
             BufferedReader reader = new BufferedReader(isr);
 
-            Pattern endOfStatement = Pattern.compile(";\\s*(?:--.*)$");
+            Pattern endOfStatement = Pattern.compile(";\\s*(?:--.*)?$");
 
             String line;
             String sqlStatement = null;
@@ -121,8 +129,9 @@ public class MobileLedgerDatabase extends SQLiteOpenHelper {
             }
 
             if (sqlStatement != null)
-                throw new RuntimeException(
-                        String.format("Error applying %s: EOF after continuation", revFile));
+                throw new RuntimeException(String.format(
+                        "Error applying %s: EOF after continuation. Line %s, Incomplete " +
+                        "statement: %s", revFile, lineNo, sqlStatement));
 
         }
         catch (IOException e) {