From 1be8eb3dac1f2cbf8a87d5608265cb54a3427ce7 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Thu, 18 Feb 2021 20:41:41 +0200 Subject: [PATCH] another approach at supporting multi-line SQL statements --- .../mobileledger/utils/MobileLedgerDatabase.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) 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 { -- 2.39.5