]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java
describe profiles for Room
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / utils / MobileLedgerDatabase.java
index 0ddaa1dc0fc2da4cb5f3c1f9a2dd9fa5684b37f1..ac78e23128d5c6994e2f152e33402def4a639543 100644 (file)
@@ -40,7 +40,7 @@ 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;
 
@@ -88,11 +88,10 @@ public class MobileLedgerDatabase extends SQLiteOpenHelper {
             InputStreamReader isr = new InputStreamReader(res);
             BufferedReader reader = new BufferedReader(isr);
 
-            Pattern continuation = Pattern.compile("\\\\\\s*$");
+            Pattern endOfStatement = Pattern.compile(";\\s*(?:--.*)?$");
 
             String line;
             String sqlStatement = null;
-            boolean eolPending;
             int lineNo = 0;
             while ((line = reader.readLine()) != null) {
                 lineNo++;
@@ -101,19 +100,13 @@ public class MobileLedgerDatabase extends SQLiteOpenHelper {
                 if (line.isEmpty())
                     continue;
 
-                Matcher m = continuation.matcher(line);
-                eolPending = false;
-                if (m.find()) {
-                    line = m.replaceFirst("");
-                    eolPending = true;
-                }
-
                 if (sqlStatement == null)
                     sqlStatement = line;
                 else
                     sqlStatement = sqlStatement.concat(line);
 
-                if (eolPending)
+                Matcher m = endOfStatement.matcher(line);
+                if (!m.find())
                     continue;
 
                 try {
@@ -128,8 +121,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) {