]> git.ktnx.net Git - mobile-ledger.git/commitdiff
another approach at supporting multi-line SQL statements
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 18 Feb 2021 18:41:41 +0000 (20:41 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 18 Feb 2021 18:41:41 +0000 (20:41 +0200)
app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java

index 0ddaa1dc0fc2da4cb5f3c1f9a2dd9fa5684b37f1..96f022b4ace6322765bb81acce5e83fa34e62a24 100644 (file)
@@ -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 {