From: Damyan Ivanov Date: Thu, 18 Feb 2021 18:41:41 +0000 (+0200) Subject: another approach at supporting multi-line SQL statements X-Git-Tag: v0.17.0~85 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=1be8eb3dac1f2cbf8a87d5608265cb54a3427ce7;p=mobile-ledger.git another approach at supporting multi-line SQL statements --- diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java b/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java index 0ddaa1dc..96f022b4 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java @@ -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 {