@capacitor-community/sqlite 5.5.1 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +1 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +217 -218
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ExportToJson.java +1 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +103 -102
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsFile.java +1 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsMigrate.java +1 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLStatement.java +1 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web-typeorm-utils/database.d.ts +21 -0
- package/dist/esm/web-typeorm-utils/database.js +91 -0
- package/dist/esm/web-typeorm-utils/database.js.map +1 -0
- package/dist/esm/web-typeorm-utils/utilsSQLite.d.ts +28 -0
- package/dist/esm/web-typeorm-utils/utilsSQLite.js +233 -0
- package/dist/esm/web-typeorm-utils/utilsSQLite.js.map +1 -0
- package/dist/esm/web.d.ts +4 -2
- package/dist/esm/web.js +210 -56
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +519 -49
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +519 -49
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +14 -6
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +3 -4
- package/ios/Plugin/Database.swift +3 -1
- package/ios/Plugin/Utils/UtilsDelete.swift +1 -1
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +1 -2
- package/ios/Plugin/Utils/UtilsSQLStatement.swift +35 -37
- package/package.json +6 -6
- package/src/definitions.ts +0 -1
- package/src/web-typeorm-utils/database.ts +111 -0
- package/src/web-typeorm-utils/utilsSQLite.ts +249 -0
- package/src/web.ts +212 -62
package/README.md
CHANGED
|
@@ -281,6 +281,8 @@ npm install --save-dev electron-builder@24.6.4
|
|
|
281
281
|
|
|
282
282
|
- [Type ORM](https://github.com/capacitor-community/sqlite/blob/master/docs/TypeORM-Usage.md)
|
|
283
283
|
|
|
284
|
+
- [TypeORM-From-5.6.0](https://github.com/capacitor-community/sqlite/blob/master/docs/TypeORM-Usage-From-5.6.0.md)
|
|
285
|
+
|
|
284
286
|
- [Web Usage](https://github.com/capacitor-community/sqlite/blob/master/docs/Web-Usage.md)
|
|
285
287
|
|
|
286
288
|
- [Non Conformed Databases](https://github.com/capacitor-community/sqlite/blob/master/docs/NonConformedDatabases.md)
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java
CHANGED
|
@@ -34,7 +34,6 @@ import java.util.List;
|
|
|
34
34
|
import java.util.Objects;
|
|
35
35
|
import java.util.regex.Matcher;
|
|
36
36
|
import java.util.regex.Pattern;
|
|
37
|
-
|
|
38
37
|
import net.sqlcipher.Cursor;
|
|
39
38
|
import net.sqlcipher.database.SQLiteDatabase;
|
|
40
39
|
import net.sqlcipher.database.SQLiteException;
|
|
@@ -190,7 +189,7 @@ public class Database {
|
|
|
190
189
|
Log.v(TAG, msg);
|
|
191
190
|
throw new Exception(msg);
|
|
192
191
|
} finally {
|
|
193
|
-
|
|
192
|
+
_db.endTransaction();
|
|
194
193
|
}
|
|
195
194
|
} else {
|
|
196
195
|
throw new Exception("Database not opened");
|
|
@@ -465,24 +464,23 @@ public class Database {
|
|
|
465
464
|
// optimize executeSet
|
|
466
465
|
Boolean isArray = valuesJson.length() > 0 ? _uSqlite.parse(valuesJson.get(0)) : false;
|
|
467
466
|
if (isArray) {
|
|
468
|
-
|
|
467
|
+
respSet = multipleRowsStatement(statement, valuesJson, returnMode);
|
|
469
468
|
} else {
|
|
470
|
-
|
|
469
|
+
respSet = oneRowStatement(statement, valuesJson, returnMode);
|
|
471
470
|
}
|
|
472
471
|
lastId = respSet.getLong("lastId");
|
|
473
472
|
if (lastId.equals(-1L)) break;
|
|
474
473
|
response = addToResponse(response, respSet);
|
|
475
|
-
|
|
476
474
|
}
|
|
477
475
|
if (lastId.equals(-1L)) {
|
|
478
|
-
|
|
476
|
+
throw new Exception("lastId equals -1");
|
|
479
477
|
} else {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
478
|
+
if (transaction) commitTransaction();
|
|
479
|
+
changes = _uSqlite.dbChanges(_db) - initChanges;
|
|
480
|
+
retObj.put("changes", changes);
|
|
481
|
+
retObj.put("lastId", lastId);
|
|
482
|
+
retObj.put("values", response.getJSONArray("values"));
|
|
483
|
+
return retObj;
|
|
486
484
|
}
|
|
487
485
|
} else {
|
|
488
486
|
throw new Exception("Database not opened");
|
|
@@ -493,77 +491,76 @@ public class Database {
|
|
|
493
491
|
if (_db != null && transaction && _db.inTransaction()) rollbackTransaction();
|
|
494
492
|
}
|
|
495
493
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
494
|
+
|
|
495
|
+
public JSObject multipleRowsStatement(String statement, JSONArray valuesJson, String returnMode) throws Exception {
|
|
496
|
+
StringBuilder sqlBuilder = new StringBuilder();
|
|
497
|
+
try {
|
|
498
|
+
for (int j = 0; j < valuesJson.length(); j++) {
|
|
499
|
+
JSONArray innerArray = valuesJson.getJSONArray(j);
|
|
500
|
+
StringBuilder innerSqlBuilder = new StringBuilder();
|
|
501
|
+
for (int k = 0; k < innerArray.length(); k++) {
|
|
502
|
+
Object innerElement = innerArray.get(k);
|
|
503
|
+
String elementValue = "";
|
|
504
|
+
|
|
505
|
+
if (innerElement instanceof String) {
|
|
506
|
+
elementValue = "'" + innerElement + "'";
|
|
507
|
+
} else {
|
|
508
|
+
elementValue = String.valueOf(innerElement);
|
|
509
|
+
}
|
|
510
|
+
innerSqlBuilder.append(elementValue);
|
|
511
|
+
|
|
512
|
+
if (k < innerArray.length() - 1) {
|
|
513
|
+
innerSqlBuilder.append(",");
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
sqlBuilder.append("(").append(innerSqlBuilder.toString()).append(")");
|
|
518
|
+
|
|
519
|
+
if (j < valuesJson.length() - 1) {
|
|
520
|
+
sqlBuilder.append(",");
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
sqlBuilder.append(";");
|
|
524
|
+
String questionMark = extractQuestionMarkValues(statement);
|
|
525
|
+
String finalSql = "";
|
|
526
|
+
if (questionMark != null) {
|
|
527
|
+
finalSql = statement.replace(questionMark, sqlBuilder.toString());
|
|
509
528
|
} else {
|
|
510
|
-
|
|
529
|
+
finalSql = statement;
|
|
511
530
|
}
|
|
512
|
-
innerSqlBuilder.append(elementValue);
|
|
513
531
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
532
|
+
JSObject respSet = prepareSQL(finalSql, new ArrayList<>(), false, returnMode);
|
|
533
|
+
return respSet;
|
|
534
|
+
} catch (Exception e) {
|
|
535
|
+
throw new Exception(e.getMessage());
|
|
536
|
+
}
|
|
537
|
+
}
|
|
518
538
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
539
|
+
public String extractQuestionMarkValues(String input) {
|
|
540
|
+
Pattern pattern = Pattern.compile("VALUES \\((\\?(?:,\\s*\\?\\s*)*)\\)");
|
|
541
|
+
Matcher matcher = pattern.matcher(input);
|
|
522
542
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
}
|
|
527
|
-
sqlBuilder.append(";");
|
|
528
|
-
String questionMark = extractQuestionMarkValues(statement);
|
|
529
|
-
String finalSql = "";
|
|
530
|
-
if(questionMark != null) {
|
|
531
|
-
finalSql = statement.replace(questionMark, sqlBuilder.toString());
|
|
543
|
+
if (matcher.find()) {
|
|
544
|
+
String extractedSubstring = matcher.group(1);
|
|
545
|
+
return "(" + extractedSubstring.replaceAll("\\s*,\\s*", ",") + ")";
|
|
532
546
|
} else {
|
|
533
|
-
|
|
547
|
+
return null;
|
|
534
548
|
}
|
|
535
|
-
|
|
536
|
-
JSObject respSet = prepareSQL(finalSql, new ArrayList<>(),
|
|
537
|
-
false, returnMode);
|
|
538
|
-
return respSet;
|
|
539
|
-
} catch (Exception e) {
|
|
540
|
-
throw new Exception(e.getMessage());
|
|
541
|
-
}
|
|
542
549
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
String returnMode) throws Exception {
|
|
556
|
-
ArrayList<Object> values = new ArrayList<>();
|
|
557
|
-
for (int j = 0; j < valuesJson.length(); j++) {
|
|
558
|
-
values.add(valuesJson.get(j));
|
|
559
|
-
}
|
|
560
|
-
try {
|
|
561
|
-
JSObject respSet = prepareSQL(statement, values, false, returnMode);
|
|
562
|
-
return respSet;
|
|
563
|
-
} catch (Exception e) {
|
|
564
|
-
throw new Exception(e.getMessage());
|
|
565
|
-
}
|
|
550
|
+
|
|
551
|
+
public JSObject oneRowStatement(String statement, JSONArray valuesJson, String returnMode) throws Exception {
|
|
552
|
+
ArrayList<Object> values = new ArrayList<>();
|
|
553
|
+
for (int j = 0; j < valuesJson.length(); j++) {
|
|
554
|
+
values.add(valuesJson.get(j));
|
|
555
|
+
}
|
|
556
|
+
try {
|
|
557
|
+
JSObject respSet = prepareSQL(statement, values, false, returnMode);
|
|
558
|
+
return respSet;
|
|
559
|
+
} catch (Exception e) {
|
|
560
|
+
throw new Exception(e.getMessage());
|
|
561
|
+
}
|
|
566
562
|
}
|
|
563
|
+
|
|
567
564
|
public JSObject addToResponse(JSObject response, JSObject respSet) throws JSONException {
|
|
568
565
|
JSObject retResp = response;
|
|
569
566
|
long lastId = respSet.getLong("lastId");
|
|
@@ -647,71 +644,71 @@ public class Database {
|
|
|
647
644
|
JSObject retObject = new JSObject();
|
|
648
645
|
String colNames = "";
|
|
649
646
|
long initLastId = (long) -1;
|
|
650
|
-
/* if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) {
|
|
647
|
+
/* if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) {
|
|
651
648
|
retMode = returnMode;
|
|
652
649
|
throw new Exception(retMode +"Not implemented for above TIRAMISU");
|
|
653
650
|
} else {
|
|
654
651
|
|
|
655
652
|
*/
|
|
656
|
-
|
|
657
|
-
|
|
653
|
+
retMode = returnMode;
|
|
654
|
+
if (!retMode.equals("no")) {
|
|
658
655
|
retMode = "wA" + retMode;
|
|
659
|
-
|
|
660
|
-
|
|
656
|
+
}
|
|
657
|
+
// }
|
|
661
658
|
if (retMode.equals("no") || retMode.substring(0, Math.min(retMode.length(), 2)).equals("wA")) {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
659
|
+
// get the statement and the returning column names
|
|
660
|
+
try {
|
|
661
|
+
JSObject stmtObj = getStmtAndRetColNames(sqlStmt, retMode);
|
|
662
|
+
sqlStmt = stmtObj.getString("stmt", sqlStmt);
|
|
663
|
+
colNames = stmtObj.getString("names", "");
|
|
664
|
+
} catch (JSONException e) {
|
|
665
|
+
throw new Exception(e.getMessage());
|
|
666
|
+
}
|
|
670
667
|
}
|
|
671
668
|
try {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
669
|
+
if (!fromJson && stmtType.equals("DELETE")) {
|
|
670
|
+
sqlStmt = deleteSQL(this, sqlStmt, values);
|
|
671
|
+
}
|
|
672
|
+
if (sqlStmt != null) {
|
|
676
673
|
stmt = _db.compileStatement(sqlStmt);
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
}
|
|
680
|
-
if (values != null && values.size() > 0) {
|
|
681
|
-
// retMode = "no";
|
|
682
|
-
Object[] valObj = new Object[values.size()];
|
|
683
|
-
for (int i = 0; i < values.size(); i++) {
|
|
684
|
-
if (values.get(i) == null) {
|
|
685
|
-
valObj[i] = null;
|
|
686
|
-
} else if (JSONObject.NULL == values.get(i)) {
|
|
687
|
-
valObj[i] = null;
|
|
688
|
-
} else {
|
|
689
|
-
valObj[i] = values.get(i);
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
SimpleSQLiteQuery.bind(stmt, valObj);
|
|
693
|
-
}
|
|
694
|
-
initLastId = _uSqlite.dbLastId(_db);
|
|
695
|
-
if (stmtType.equals("INSERT")) {
|
|
696
|
-
stmt.executeInsert();
|
|
697
|
-
} else {
|
|
698
|
-
if (retMode.startsWith("wA") && colNames.length() > 0 && stmtType.equals("DELETE")) {
|
|
699
|
-
retValues = getUpdDelReturnedValues(this, sqlStmt, colNames);
|
|
674
|
+
} else {
|
|
675
|
+
throw new Exception("sqlStmt is null");
|
|
700
676
|
}
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
677
|
+
if (values != null && values.size() > 0) {
|
|
678
|
+
// retMode = "no";
|
|
679
|
+
Object[] valObj = new Object[values.size()];
|
|
680
|
+
for (int i = 0; i < values.size(); i++) {
|
|
681
|
+
if (values.get(i) == null) {
|
|
682
|
+
valObj[i] = null;
|
|
683
|
+
} else if (JSONObject.NULL == values.get(i)) {
|
|
684
|
+
valObj[i] = null;
|
|
685
|
+
} else {
|
|
686
|
+
valObj[i] = values.get(i);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
SimpleSQLiteQuery.bind(stmt, valObj);
|
|
690
|
+
}
|
|
691
|
+
initLastId = _uSqlite.dbLastId(_db);
|
|
705
692
|
if (stmtType.equals("INSERT")) {
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
693
|
+
stmt.executeInsert();
|
|
694
|
+
} else {
|
|
695
|
+
if (retMode.startsWith("wA") && colNames.length() > 0 && stmtType.equals("DELETE")) {
|
|
696
|
+
retValues = getUpdDelReturnedValues(this, sqlStmt, colNames);
|
|
709
697
|
}
|
|
710
|
-
|
|
711
|
-
retValues = getUpdDelReturnedValues(this, sqlStmt, colNames);
|
|
698
|
+
stmt.executeUpdateDelete();
|
|
712
699
|
}
|
|
713
|
-
|
|
714
|
-
|
|
700
|
+
Long lastId = _uSqlite.dbLastId(_db);
|
|
701
|
+
if (retMode.startsWith("wA") && colNames.length() > 0) {
|
|
702
|
+
if (stmtType.equals("INSERT")) {
|
|
703
|
+
String tableName = extractTableName(sqlStmt);
|
|
704
|
+
if (tableName != null) {
|
|
705
|
+
retValues = getInsertReturnedValues(this, colNames, tableName, initLastId, lastId, retMode);
|
|
706
|
+
}
|
|
707
|
+
} else if (stmtType.equals("UPDATE")) {
|
|
708
|
+
retValues = getUpdDelReturnedValues(this, sqlStmt, colNames);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
/*
|
|
715
712
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) {
|
|
716
713
|
|
|
717
714
|
if (retMode.startsWith("one") || retMode.startsWith("all")) {
|
|
@@ -719,9 +716,9 @@ public class Database {
|
|
|
719
716
|
}
|
|
720
717
|
}
|
|
721
718
|
*/
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
719
|
+
retObject.put("lastId", lastId);
|
|
720
|
+
retObject.put("values", retValues);
|
|
721
|
+
return retObject;
|
|
725
722
|
} catch (Exception e) {
|
|
726
723
|
throw new Exception(e.getMessage());
|
|
727
724
|
} finally {
|
|
@@ -737,107 +734,107 @@ public class Database {
|
|
|
737
734
|
Boolean isReturning = retIsReturning.getBoolean("isReturning");
|
|
738
735
|
String stmt = retIsReturning.getString("stmt");
|
|
739
736
|
String suffix = retIsReturning.getString("names");
|
|
740
|
-
retObj.put("stmt",stmt);
|
|
741
|
-
retObj.put("names","");
|
|
737
|
+
retObj.put("stmt", stmt);
|
|
738
|
+
retObj.put("names", "");
|
|
742
739
|
|
|
743
740
|
if (isReturning && retMode.startsWith("wA")) {
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
741
|
+
String lowercaseSuffix = suffix != null ? suffix.toLowerCase() : "";
|
|
742
|
+
int returningIndex = lowercaseSuffix.indexOf("returning");
|
|
743
|
+
if (returningIndex != -1) {
|
|
744
|
+
String substring = suffix.substring(returningIndex + "returning".length());
|
|
745
|
+
String names = substring.trim();
|
|
746
|
+
if (names.endsWith(";")) {
|
|
747
|
+
retObj.put("names", names.substring(0, names.length() - 1));
|
|
748
|
+
}
|
|
752
749
|
}
|
|
753
|
-
}
|
|
754
750
|
}
|
|
755
751
|
return retObj;
|
|
756
752
|
}
|
|
757
753
|
|
|
758
754
|
private JSObject isReturning(String sqlStmt) {
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
String stmt = sqlStmt.replace("\n", "").trim();
|
|
762
|
-
if (stmt.endsWith(";")) {
|
|
763
|
-
// Remove the suffix
|
|
764
|
-
stmt = stmt.substring(0, stmt.length() - 1).trim();
|
|
765
|
-
}
|
|
766
|
-
retObj.put("isReturning",false);
|
|
767
|
-
retObj.put("stmt",stmt);
|
|
768
|
-
retObj.put("names","");
|
|
769
|
-
|
|
770
|
-
switch (stmt.substring(0, Math.min(stmt.length(), 6)).toUpperCase()) {
|
|
771
|
-
case "INSERT":
|
|
772
|
-
int valuesIndex = stmt.toUpperCase().indexOf("VALUES");
|
|
773
|
-
if (valuesIndex != -1) {
|
|
774
|
-
|
|
775
|
-
int closingParenthesisIndex = -1;
|
|
776
|
-
|
|
777
|
-
for (int i = stmt.length() - 1; i >= valuesIndex; i--) {
|
|
778
|
-
if (stmt.charAt(i) == ')') {
|
|
779
|
-
closingParenthesisIndex = i;
|
|
780
|
-
break;
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
if (closingParenthesisIndex != -1) {
|
|
784
|
-
String stmtString = stmt.substring(0, closingParenthesisIndex + 1).trim() + ";";
|
|
785
|
-
String resultString = stmt.substring(closingParenthesisIndex + 1).trim();
|
|
786
|
-
if (resultString.length() > 0 && !resultString.endsWith(";")) {
|
|
787
|
-
resultString += ";";
|
|
788
|
-
}
|
|
789
|
-
if (resultString.toLowerCase().contains("returning")) {
|
|
790
|
-
retObj.put("isReturning", true);
|
|
791
|
-
retObj.put("stmt", stmtString);
|
|
792
|
-
retObj.put("names", resultString);
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
return retObj;
|
|
797
|
-
case "DELETE":
|
|
798
|
-
case "UPDATE":
|
|
799
|
-
String[] words = stmt.split("\\s+");
|
|
800
|
-
List<String> wordsBeforeReturning = new ArrayList<>();
|
|
801
|
-
List<String> returningString = new ArrayList<>();
|
|
802
|
-
|
|
803
|
-
boolean isReturningOutsideMessage = false;
|
|
804
|
-
for (String word : words) {
|
|
805
|
-
if (word.toLowerCase().equals("returning")) {
|
|
806
|
-
isReturningOutsideMessage = true;
|
|
807
|
-
// Include "RETURNING" and the words after it in returningString
|
|
808
|
-
returningString.add(word);
|
|
809
|
-
returningString.addAll(wordsAfter(word, words));
|
|
810
|
-
break;
|
|
811
|
-
}
|
|
812
|
-
wordsBeforeReturning.add(word);
|
|
813
|
-
}
|
|
755
|
+
JSObject retObj = new JSObject();
|
|
814
756
|
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
757
|
+
String stmt = sqlStmt.replace("\n", "").trim();
|
|
758
|
+
if (stmt.endsWith(";")) {
|
|
759
|
+
// Remove the suffix
|
|
760
|
+
stmt = stmt.substring(0, stmt.length() - 1).trim();
|
|
761
|
+
}
|
|
762
|
+
retObj.put("isReturning", false);
|
|
763
|
+
retObj.put("stmt", stmt);
|
|
764
|
+
retObj.put("names", "");
|
|
765
|
+
|
|
766
|
+
switch (stmt.substring(0, Math.min(stmt.length(), 6)).toUpperCase()) {
|
|
767
|
+
case "INSERT":
|
|
768
|
+
int valuesIndex = stmt.toUpperCase().indexOf("VALUES");
|
|
769
|
+
if (valuesIndex != -1) {
|
|
770
|
+
int closingParenthesisIndex = -1;
|
|
771
|
+
|
|
772
|
+
for (int i = stmt.length() - 1; i >= valuesIndex; i--) {
|
|
773
|
+
if (stmt.charAt(i) == ')') {
|
|
774
|
+
closingParenthesisIndex = i;
|
|
775
|
+
break;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
if (closingParenthesisIndex != -1) {
|
|
779
|
+
String stmtString = stmt.substring(0, closingParenthesisIndex + 1).trim() + ";";
|
|
780
|
+
String resultString = stmt.substring(closingParenthesisIndex + 1).trim();
|
|
781
|
+
if (resultString.length() > 0 && !resultString.endsWith(";")) {
|
|
782
|
+
resultString += ";";
|
|
783
|
+
}
|
|
784
|
+
if (resultString.toLowerCase().contains("returning")) {
|
|
785
|
+
retObj.put("isReturning", true);
|
|
786
|
+
retObj.put("stmt", stmtString);
|
|
787
|
+
retObj.put("names", resultString);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
return retObj;
|
|
792
|
+
case "DELETE":
|
|
793
|
+
case "UPDATE":
|
|
794
|
+
String[] words = stmt.split("\\s+");
|
|
795
|
+
List<String> wordsBeforeReturning = new ArrayList<>();
|
|
796
|
+
List<String> returningString = new ArrayList<>();
|
|
797
|
+
|
|
798
|
+
boolean isReturningOutsideMessage = false;
|
|
799
|
+
for (String word : words) {
|
|
800
|
+
if (word.toLowerCase().equals("returning")) {
|
|
801
|
+
isReturningOutsideMessage = true;
|
|
802
|
+
// Include "RETURNING" and the words after it in returningString
|
|
803
|
+
returningString.add(word);
|
|
804
|
+
returningString.addAll(wordsAfter(word, words));
|
|
805
|
+
break;
|
|
806
|
+
}
|
|
807
|
+
wordsBeforeReturning.add(word);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
if (isReturningOutsideMessage) {
|
|
811
|
+
String joinedWords = String.join(" ", wordsBeforeReturning) + ";";
|
|
812
|
+
String joinedReturningString = String.join(" ", returningString);
|
|
813
|
+
if (joinedReturningString.length() > 0 && !joinedReturningString.endsWith(";")) {
|
|
814
|
+
joinedReturningString += ";";
|
|
815
|
+
}
|
|
816
|
+
retObj.put("isReturning", true);
|
|
817
|
+
retObj.put("stmt", joinedWords);
|
|
818
|
+
retObj.put("names", joinedReturningString);
|
|
819
|
+
return retObj;
|
|
820
|
+
} else {
|
|
821
|
+
return retObj;
|
|
822
|
+
}
|
|
823
|
+
default:
|
|
824
|
+
return retObj;
|
|
825
|
+
}
|
|
831
826
|
}
|
|
827
|
+
|
|
832
828
|
private List<String> wordsAfter(String word, String[] words) {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
829
|
+
List<String> mWords = Arrays.asList(words);
|
|
830
|
+
int index = mWords.indexOf(word);
|
|
831
|
+
if (index == -1) {
|
|
832
|
+
return new ArrayList<>();
|
|
833
|
+
}
|
|
834
|
+
List<String> retWords = new ArrayList<>(mWords.subList(index + 1, mWords.size()));
|
|
835
|
+
return retWords;
|
|
840
836
|
}
|
|
837
|
+
|
|
841
838
|
private JSArray getInsertReturnedValues(Database mDB, String colNames, String tableName, Long iLastId, Long lastId, String rMode)
|
|
842
839
|
throws Exception {
|
|
843
840
|
JSArray retVals = new JSArray();
|
|
@@ -1181,7 +1178,9 @@ public class Database {
|
|
|
1181
1178
|
long syncTime = date.getTime() / 1000L;
|
|
1182
1179
|
toJson.setLastExportDate(this, syncTime);
|
|
1183
1180
|
} else {
|
|
1184
|
-
|
|
1181
|
+
if (inJson.getMode().equals("partial")) {
|
|
1182
|
+
throw new Exception("No sync_table available");
|
|
1183
|
+
}
|
|
1185
1184
|
}
|
|
1186
1185
|
// launch the export process
|
|
1187
1186
|
JsonSQLite retJson = toJson.createExportObject(this, inJson);
|
|
@@ -362,7 +362,7 @@ public class ExportToJson {
|
|
|
362
362
|
String pk = sc.substring(oPar + 1, cPar);
|
|
363
363
|
row[0] = "CPK_" + pk.replaceAll("§", "_");
|
|
364
364
|
row[0] = row[0].replaceAll("_ ", "_");
|
|
365
|
-
row[1] = sc.substring(cPar +
|
|
365
|
+
row[1] = sc.substring(0, cPar + 1);
|
|
366
366
|
jsonRow.setConstraint(row[0]);
|
|
367
367
|
}
|
|
368
368
|
case "CONSTRAINT" -> {
|