@capacitor-community/sqlite 5.0.5-2 → 5.0.5

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.
Files changed (35) hide show
  1. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +109 -156
  2. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +81 -249
  3. package/android/src/main/java/com/getcapacitor/community/database/sqlite/NotificationCenter.java +1 -1
  4. package/android/src/main/java/com/getcapacitor/community/database/sqlite/RetHandler.java +0 -12
  5. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +175 -40
  6. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ExportToJson.java +141 -135
  7. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +2 -1
  8. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsBiometric.java +0 -4
  9. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsFile.java +30 -18
  10. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsMigrate.java +12 -4
  11. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsNCDatabase.java +4 -1
  12. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLCipher.java +8 -6
  13. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLite.java +14 -28
  14. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSecret.java +0 -1
  15. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +0 -1
  16. package/dist/esm/definitions.d.ts +25 -4
  17. package/dist/esm/definitions.js +42 -19
  18. package/dist/esm/definitions.js.map +1 -1
  19. package/dist/plugin.cjs.js +42 -19
  20. package/dist/plugin.cjs.js.map +1 -1
  21. package/dist/plugin.js +42 -19
  22. package/dist/plugin.js.map +1 -1
  23. package/electron/dist/plugin.js +195 -96
  24. package/electron/dist/plugin.js.map +1 -1
  25. package/ios/Plugin/CapacitorSQLite.swift +8 -4
  26. package/ios/Plugin/CapacitorSQLitePlugin.swift +6 -3
  27. package/ios/Plugin/Database.swift +28 -14
  28. package/ios/Plugin/ImportExportJson/ExportToJson.swift +10 -5
  29. package/ios/Plugin/ImportExportJson/ImportFromJson.swift +4 -2
  30. package/ios/Plugin/Utils/UtilsDownloadFromHTTP.swift +61 -61
  31. package/ios/Plugin/Utils/UtilsDrop.swift +2 -1
  32. package/ios/Plugin/Utils/UtilsSQLCipher.swift +255 -23
  33. package/ios/Plugin/Utils/UtilsUpgrade.swift +0 -1
  34. package/package.json +2 -2
  35. package/src/definitions.ts +67 -18
@@ -84,28 +84,28 @@ class UtilsFile {
84
84
  else {
85
85
  this.capConfig = JSON.parse(this.NodeFs.readFileSync(this.Path.join(this.appPath, 'capacitor.config.json')).toString());
86
86
  }
87
- this.isEncryption = this.capConfig.plugins.CapacitorSQLite.electronIsEncryption
87
+ this.isEncryption = this.capConfig.plugins.CapacitorSQLite
88
+ .electronIsEncryption
88
89
  ? this.capConfig.plugins.CapacitorSQLite.electronIsEncryption
89
90
  : false;
90
91
  this.osType = this.Os.type();
91
92
  switch (this.osType) {
92
93
  case 'Darwin':
93
- this.pathDB =
94
- this.capConfig.plugins.CapacitorSQLite.electronMacLocation
95
- ? this.capConfig.plugins.CapacitorSQLite.electronMacLocation
96
- : 'Databases';
94
+ this.pathDB = this.capConfig.plugins.CapacitorSQLite.electronMacLocation
95
+ ? this.capConfig.plugins.CapacitorSQLite.electronMacLocation
96
+ : 'Databases';
97
97
  break;
98
98
  case 'Linux':
99
- this.pathDB =
100
- this.capConfig.plugins.CapacitorSQLite.electronLinuxLocation
101
- ? this.capConfig.plugins.CapacitorSQLite.electronLinuxLocation
102
- : 'Databases';
99
+ this.pathDB = this.capConfig.plugins.CapacitorSQLite
100
+ .electronLinuxLocation
101
+ ? this.capConfig.plugins.CapacitorSQLite.electronLinuxLocation
102
+ : 'Databases';
103
103
  break;
104
104
  case 'Windows_NT':
105
- this.pathDB =
106
- this.capConfig.plugins.CapacitorSQLite.electronWindowsLocation
107
- ? this.capConfig.plugins.CapacitorSQLite.electronWindowsLocation
108
- : 'Databases';
105
+ this.pathDB = this.capConfig.plugins.CapacitorSQLite
106
+ .electronWindowsLocation
107
+ ? this.capConfig.plugins.CapacitorSQLite.electronWindowsLocation
108
+ : 'Databases';
109
109
  break;
110
110
  default:
111
111
  console.log('other operating system');
@@ -799,7 +799,7 @@ class UtilsSQLite {
799
799
  */
800
800
  changePassword(pathDB, password, newpassword) {
801
801
  let mDB;
802
- const msg = "ChangePassword";
802
+ const msg = 'ChangePassword';
803
803
  try {
804
804
  mDB = this.openOrCreateDatabase(pathDB, password, false);
805
805
  this.pragmaReKey(mDB, password, newpassword);
@@ -944,16 +944,16 @@ class UtilsSQLite {
944
944
  */
945
945
  execute(mDB, sql, fromJson) {
946
946
  const result = { changes: 0, lastId: -1 };
947
- const msg = "Execute";
947
+ const msg = 'Execute';
948
948
  let changes = -1;
949
949
  let lastId = -1;
950
950
  let initChanges = -1;
951
951
  try {
952
952
  initChanges = this.dbChanges(mDB);
953
953
  let sqlStmt = sql;
954
- if (sql.toLowerCase().includes('DELETE FROM'.toLowerCase())
955
- || sql.toLowerCase().includes('INSERT INTO'.toLowerCase())
956
- || sql.toLowerCase().includes('UPDATE'.toLowerCase())) {
954
+ if (sql.toLowerCase().includes('DELETE FROM'.toLowerCase()) ||
955
+ sql.toLowerCase().includes('INSERT INTO'.toLowerCase()) ||
956
+ sql.toLowerCase().includes('UPDATE'.toLowerCase())) {
957
957
  sqlStmt = this.checkStatements(mDB, sql, fromJson);
958
958
  }
959
959
  this.execDB(mDB, sqlStmt);
@@ -972,8 +972,8 @@ class UtilsSQLite {
972
972
  // split the statements in an array of statement
973
973
  let sqlStmt = sql.replace(/\n/g, '');
974
974
  // deal with trigger
975
- sqlStmt = sqlStmt.replace(/end;/g, "END;");
976
- sqlStmt = sqlStmt.replace(/;END;/g, "&END;");
975
+ sqlStmt = sqlStmt.replace(/end;/g, 'END;');
976
+ sqlStmt = sqlStmt.replace(/;END;/g, '&END;');
977
977
  const sqlStmts = sqlStmt.split(';');
978
978
  const resArr = [];
979
979
  // loop through the statement
@@ -986,12 +986,11 @@ class UtilsSQLite {
986
986
  switch (method) {
987
987
  case 'CREATE':
988
988
  if (rStmt.includes('&END')) {
989
- rStmt = rStmt.replace(/&END/g, ";END");
989
+ rStmt = rStmt.replace(/&END/g, ';END');
990
990
  }
991
991
  break;
992
992
  case 'DELETE':
993
- if (!fromJson &&
994
- stmt.toLowerCase().includes('WHERE'.toLowerCase())) {
993
+ if (!fromJson && stmt.toLowerCase().includes('WHERE'.toLowerCase())) {
995
994
  const whereStmt = this.cleanStatement(`${stmt.trim()}`);
996
995
  rStmt = this.deleteSQL(mDB, whereStmt, []);
997
996
  }
@@ -1007,8 +1006,7 @@ class UtilsSQLite {
1007
1006
  }
1008
1007
  break;
1009
1008
  case 'SELECT':
1010
- if (!fromJson &&
1011
- stmt.toLowerCase().includes('WHERE'.toLowerCase())) {
1009
+ if (!fromJson && stmt.toLowerCase().includes('WHERE'.toLowerCase())) {
1012
1010
  rStmt = this.cleanStatement(`${stmt.trim()}`);
1013
1011
  }
1014
1012
  break;
@@ -1040,10 +1038,10 @@ class UtilsSQLite {
1040
1038
  * @param set
1041
1039
  * @param fromJson
1042
1040
  */
1043
- executeSet(mDB, set, fromJson) {
1044
- const ret = { changes: 0, lastId: -1 };
1041
+ executeSet(mDB, set, fromJson, returnMode) {
1042
+ const ret = { changes: 0, lastId: -1, values: [] };
1045
1043
  let result = { changes: 0, lastId: -1 };
1046
- const msg = "ExecuteSet";
1044
+ const msg = 'ExecuteSet';
1047
1045
  for (let i = 0; i < set.length; i++) {
1048
1046
  const statement = 'statement' in set[i] ? set[i].statement : null;
1049
1047
  const values = 'values' in set[i] && set[i].values.length > 0 ? set[i].values : [];
@@ -1056,22 +1054,28 @@ class UtilsSQLite {
1056
1054
  if (Array.isArray(values[0])) {
1057
1055
  for (const val of values) {
1058
1056
  const mVal = this.replaceUndefinedByNull(val);
1059
- result = this.prepareRun(mDB, statement, mVal, fromJson);
1057
+ result = this.prepareRun(mDB, statement, mVal, fromJson, returnMode);
1060
1058
  ret.changes += result.changes;
1061
1059
  ret.lastId = result.lastId;
1060
+ const keys = Object.keys(result);
1061
+ if (keys.includes('values') && result.values.length > 0) {
1062
+ ret.values.push(result.values);
1063
+ }
1062
1064
  }
1063
1065
  }
1064
1066
  else {
1065
1067
  if (values.length > 0) {
1066
1068
  const mVal = this.replaceUndefinedByNull(values);
1067
- result = this.prepareRun(mDB, statement, mVal, fromJson);
1068
- ret.changes += result.changes;
1069
- ret.lastId = result.lastId;
1069
+ result = this.prepareRun(mDB, statement, mVal, fromJson, returnMode);
1070
1070
  }
1071
1071
  else {
1072
- result = this.prepareRun(mDB, statement, [], fromJson);
1073
- ret.changes += result.changes;
1074
- ret.lastId = result.lastId;
1072
+ result = this.prepareRun(mDB, statement, [], fromJson, returnMode);
1073
+ }
1074
+ ret.changes += result.changes;
1075
+ ret.lastId = result.lastId;
1076
+ const keys = Object.keys(result);
1077
+ if (keys.includes('values') && result.values.length > 0) {
1078
+ ret.values.push(result.values);
1075
1079
  }
1076
1080
  }
1077
1081
  }
@@ -1089,9 +1093,9 @@ class UtilsSQLite {
1089
1093
  * @param values
1090
1094
  * @param fromJson
1091
1095
  */
1092
- prepareRun(mDB, statement, values, fromJson) {
1096
+ prepareRun(mDB, statement, values, fromJson, returnMode) {
1093
1097
  const result = { changes: 0, lastId: -1 };
1094
- const msg = "PrepareRun";
1098
+ const msg = 'PrepareRun';
1095
1099
  const stmtType = statement
1096
1100
  .replace(/\n/g, '')
1097
1101
  .trim()
@@ -1114,9 +1118,16 @@ class UtilsSQLite {
1114
1118
  mVal.push(null);
1115
1119
  }
1116
1120
  }
1117
- const ret = this.runExec(mDB, sqlStmt, mVal);
1118
- result.changes = ret.changes;
1119
- result.lastId = ret.lastInsertRowid;
1121
+ const ret = this.runExec(mDB, sqlStmt, mVal, returnMode);
1122
+ if (ret.values != null) {
1123
+ result.values = ret.values;
1124
+ result.changes = ret.changes;
1125
+ result.lastId = ret.lastInsertRowid;
1126
+ }
1127
+ else {
1128
+ result.changes = ret.changes;
1129
+ result.lastId = ret.lastInsertRowid;
1130
+ }
1120
1131
  return result;
1121
1132
  }
1122
1133
  catch (err) {
@@ -1124,17 +1135,59 @@ class UtilsSQLite {
1124
1135
  throw new Error(`${msg} ${errmsg}`);
1125
1136
  }
1126
1137
  }
1127
- runExec(mDB, stmt, values = []) {
1138
+ runExec(mDB, stmt, values = [], returnMode) {
1139
+ let result = { changes: 0, lastInsertRowid: -1, values: [] };
1128
1140
  const msg = 'runExec: ';
1129
1141
  try {
1130
1142
  const cStmt = this.cleanStatement(stmt);
1131
- const statement = mDB.prepare(cStmt);
1132
- let result;
1133
- if (values != null && values.length > 0) {
1134
- result = statement.run(values);
1135
- }
1136
- else {
1137
- result = statement.run();
1143
+ const params = this.getStmtAndNames(cStmt, returnMode);
1144
+ switch (params.mMode) {
1145
+ case 'one': {
1146
+ const iniChanges = this.dbChanges(mDB);
1147
+ if (values.length === 0) {
1148
+ const value = mDB.prepare(params.stmt).get();
1149
+ result.values.push(value);
1150
+ result.lastInsertRowid = this.getLastId(mDB);
1151
+ }
1152
+ else {
1153
+ const lowerId = this.getLastId(mDB) + 1;
1154
+ const statement = mDB.prepare(params.stmt);
1155
+ const res = statement.run(values);
1156
+ result.lastInsertRowid = res.lastInsertRowid;
1157
+ const sql = `SELECT ${params.names} FROM ${params.tableName} WHERE rowid = ${lowerId};`;
1158
+ const value = this.queryOne(mDB, sql, []);
1159
+ result.values.push(value);
1160
+ }
1161
+ result.changes = this.dbChanges(mDB) - iniChanges;
1162
+ break;
1163
+ }
1164
+ case 'all': {
1165
+ const iniChanges = this.dbChanges(mDB);
1166
+ if (values.length === 0) {
1167
+ result.values = mDB.prepare(params.stmt).all();
1168
+ result.lastInsertRowid = this.getLastId(mDB);
1169
+ }
1170
+ else {
1171
+ const lowerId = this.getLastId(mDB) + 1;
1172
+ const statement = mDB.prepare(params.stmt);
1173
+ const res = statement.run(values);
1174
+ const upperId = res.lastInsertRowid;
1175
+ const sql = `SELECT ${params.names} FROM ${params.tableName} WHERE rowid BETWEEN ${lowerId} AND ${upperId};`;
1176
+ result.values = this.queryAll(mDB, sql, []);
1177
+ result.lastInsertRowid = res.lastInsertRowid;
1178
+ }
1179
+ result.changes = this.dbChanges(mDB) - iniChanges;
1180
+ break;
1181
+ }
1182
+ default: {
1183
+ const statement = mDB.prepare(params.stmt);
1184
+ if (values != null && values.length > 0) {
1185
+ result = statement.run(values);
1186
+ }
1187
+ else {
1188
+ result = statement.run();
1189
+ }
1190
+ }
1138
1191
  }
1139
1192
  return result;
1140
1193
  }
@@ -1169,7 +1222,7 @@ class UtilsSQLite {
1169
1222
  */
1170
1223
  deleteSQL(mDB, statement, values) {
1171
1224
  let sqlStmt = statement;
1172
- const msg = "DeleteSQL";
1225
+ const msg = 'DeleteSQL';
1173
1226
  try {
1174
1227
  const isLast = this.isLastModified(mDB, true);
1175
1228
  const isDel = this.isSqlDeleted(mDB, true);
@@ -1201,7 +1254,7 @@ class UtilsSQLite {
1201
1254
  * @returns
1202
1255
  */
1203
1256
  findReferencesAndUpdate(mDB, tableName, whereStmt, values) {
1204
- const msg = "FindReferencesAndUpdate";
1257
+ const msg = 'FindReferencesAndUpdate';
1205
1258
  try {
1206
1259
  const references = this.getReferences(mDB, tableName);
1207
1260
  if (references.length <= 0) {
@@ -1252,7 +1305,7 @@ class UtilsSQLite {
1252
1305
  }
1253
1306
  }
1254
1307
  }
1255
- const ret = this.runExec(mDB, stmt, selValues);
1308
+ const ret = this.runExec(mDB, stmt, selValues, 'no');
1256
1309
  const lastId = ret.lastInsertRowid;
1257
1310
  if (lastId == -1) {
1258
1311
  const msg = `UPDATE sql_deleted failed for references table: ${refTable}`;
@@ -1349,7 +1402,7 @@ class UtilsSQLite {
1349
1402
  return whereStmt;
1350
1403
  }
1351
1404
  getReferences(mDB, tableName) {
1352
- const msg = "GetReferences";
1405
+ const msg = 'GetReferences';
1353
1406
  const sqlStmt = 'SELECT sql FROM sqlite_master ' +
1354
1407
  "WHERE sql LIKE('%FOREIGN KEY%') AND sql LIKE('%REFERENCES%') AND " +
1355
1408
  "sql LIKE('%" +
@@ -1391,7 +1444,7 @@ class UtilsSQLite {
1391
1444
  * @param values
1392
1445
  */
1393
1446
  queryAll(mDB, sql, values) {
1394
- const msg = "QueryAll";
1447
+ const msg = 'QueryAll';
1395
1448
  try {
1396
1449
  const cSql = this.cleanStatement(sql);
1397
1450
  const stmt = mDB.prepare(cSql);
@@ -1419,7 +1472,7 @@ class UtilsSQLite {
1419
1472
  * @param values
1420
1473
  */
1421
1474
  queryOne(mDB, sql, values) {
1422
- const msg = "QueryOne";
1475
+ const msg = 'QueryOne';
1423
1476
  try {
1424
1477
  const cSql = this.cleanStatement(sql);
1425
1478
  const stmt = mDB.prepare(cSql);
@@ -1442,7 +1495,7 @@ class UtilsSQLite {
1442
1495
  * @param mDb
1443
1496
  */
1444
1497
  getTablesNames(mDb) {
1445
- const msg = "getTablesNames";
1498
+ const msg = 'getTablesNames';
1446
1499
  let sql = 'SELECT name FROM sqlite_master WHERE ';
1447
1500
  sql += "type='table' AND name NOT LIKE 'sync_table' ";
1448
1501
  sql += "AND name NOT LIKE '_temp_%' ";
@@ -1466,7 +1519,7 @@ class UtilsSQLite {
1466
1519
  * @param mDb
1467
1520
  */
1468
1521
  getViewsNames(mDb) {
1469
- const msg = "GetViewsNames";
1522
+ const msg = 'GetViewsNames';
1470
1523
  let sql = 'SELECT name FROM sqlite_master WHERE ';
1471
1524
  sql += "type='view' AND name NOT LIKE 'sqlite_%' ";
1472
1525
  sql += 'ORDER BY rootpage DESC;';
@@ -1489,7 +1542,7 @@ class UtilsSQLite {
1489
1542
  * @param isOpen
1490
1543
  */
1491
1544
  isLastModified(mDB, isOpen) {
1492
- const msg = "IsLastModified";
1545
+ const msg = 'IsLastModified';
1493
1546
  if (!isOpen) {
1494
1547
  throw new Error(`${msg} database not opened`);
1495
1548
  }
@@ -1515,7 +1568,7 @@ class UtilsSQLite {
1515
1568
  * @param isOpen
1516
1569
  */
1517
1570
  isSqlDeleted(mDB, isOpen) {
1518
- const msg = "IsSqlDeleted";
1571
+ const msg = 'IsSqlDeleted';
1519
1572
  if (!isOpen) {
1520
1573
  throw new Error(`${msg} database not opened`);
1521
1574
  }
@@ -1536,10 +1589,11 @@ class UtilsSQLite {
1536
1589
  }
1537
1590
  }
1538
1591
  getJournalMode(mDB) {
1539
- const msg = "getJournalMode";
1592
+ const msg = 'getJournalMode';
1540
1593
  try {
1541
- const retMode = mDB.pragma('journal_mode')[0];
1542
- return retMode;
1594
+ const retMode = mDB.pragma('journal_mode');
1595
+ console.log(`journal_mode: ${retMode[0].journal_mode}`);
1596
+ return retMode[0].journal_mode;
1543
1597
  }
1544
1598
  catch (err) {
1545
1599
  const errmsg = err.message ? err.message : err;
@@ -1547,7 +1601,7 @@ class UtilsSQLite {
1547
1601
  }
1548
1602
  }
1549
1603
  async isDatabaseEncrypted(dbName) {
1550
- const msg = "isDatabaseEncrypted";
1604
+ const msg = 'isDatabaseEncrypted';
1551
1605
  try {
1552
1606
  const isExists = this.fileUtil.isFileExists(dbName);
1553
1607
  if (isExists) {
@@ -1565,7 +1619,10 @@ class UtilsSQLite {
1565
1619
  }
1566
1620
  async isDBEncrypted(filePath) {
1567
1621
  try {
1568
- const retStr = await this.fileUtil.readFileAsPromise(filePath, { start: 0, end: 12 });
1622
+ const retStr = await this.fileUtil.readFileAsPromise(filePath, {
1623
+ start: 0,
1624
+ end: 12,
1625
+ });
1569
1626
  if (retStr === 'SQLite format')
1570
1627
  return false;
1571
1628
  else
@@ -1581,7 +1638,7 @@ class UtilsSQLite {
1581
1638
  * @param tableName
1582
1639
  */
1583
1640
  getTableColumnNamesTypes(mDB, tableName) {
1584
- const msg = "getTableColumnNamesTypes";
1641
+ const msg = 'getTableColumnNamesTypes';
1585
1642
  try {
1586
1643
  const infos = mDB.pragma(`table_info('${tableName}')`);
1587
1644
  const retNames = [];
@@ -1598,22 +1655,21 @@ class UtilsSQLite {
1598
1655
  }
1599
1656
  }
1600
1657
  cleanStatement(stmt) {
1601
- let sql = "";
1658
+ let sql = '';
1602
1659
  if (stmt.toLowerCase().includes('INSERT INTO'.toLowerCase()) ||
1603
1660
  stmt.toLowerCase().includes('SELECT'.toLowerCase()) ||
1604
1661
  stmt.toLowerCase().includes('UPDATE'.toLowerCase()) ||
1605
1662
  stmt.toLowerCase().includes('DELETE FROM'.toLowerCase())) {
1606
1663
  // check for JSON string
1607
1664
  sql = this.dealJsonString(stmt);
1608
- sql = sql.replaceAll("\"", "'");
1609
- sql = sql.replaceAll("§", "\"");
1665
+ sql = sql.replaceAll('"', "'");
1666
+ sql = sql.replaceAll('§', '"');
1610
1667
  }
1611
1668
  else {
1612
1669
  sql = stmt;
1613
1670
  }
1614
1671
  return sql;
1615
1672
  }
1616
- ;
1617
1673
  findIndex(str, char) {
1618
1674
  const a = [];
1619
1675
  for (let i = str.length; i--;)
@@ -1626,11 +1682,54 @@ class UtilsSQLite {
1626
1682
  const oJ = this.findIndex(stmt, '{');
1627
1683
  const eJ = this.findIndex(stmt, '}');
1628
1684
  for (let i = 0; i < oJ.length; i++) {
1629
- const g = (retStmt.substring(oJ[i] + 1, eJ[i])).replaceAll("\"", "§");
1685
+ const g = retStmt.substring(oJ[i] + 1, eJ[i]).replaceAll('"', '§');
1630
1686
  retStmt = retStmt.substring(0, oJ[i] + 1) + g + retStmt.substring(eJ[i]);
1631
1687
  }
1632
1688
  return retStmt;
1633
1689
  }
1690
+ getStmtAndNames(stmt, returnMode) {
1691
+ const retObj = {};
1692
+ const mStmt = stmt;
1693
+ if (mStmt.toUpperCase().includes('RETURNING') &&
1694
+ (returnMode === 'all' || returnMode === 'one')) {
1695
+ retObj.tableName = this.getTableName(mStmt);
1696
+ retObj.mMode = returnMode;
1697
+ const idx = mStmt.toUpperCase().indexOf('RETURNING') + 9;
1698
+ const names = mStmt.substring(idx).trim();
1699
+ retObj.names = names.slice(-1) === ';' ? names.slice(0, -1) : names;
1700
+ retObj.stmt = mStmt;
1701
+ }
1702
+ else {
1703
+ retObj.mMode = 'no';
1704
+ if (mStmt.toUpperCase().includes('RETURNING')) {
1705
+ const idx = mStmt.toUpperCase().indexOf('RETURNING');
1706
+ retObj.stmt = mStmt.slice(0, idx).trim() + ';';
1707
+ }
1708
+ else {
1709
+ retObj.stmt = mStmt;
1710
+ }
1711
+ }
1712
+ return retObj;
1713
+ }
1714
+ getTableName(sqlStatement) {
1715
+ const patterns = {
1716
+ insert: /INSERT\s+INTO\s+(\w+)/i,
1717
+ delete: /DELETE\s+FROM\s+(\w+)/i,
1718
+ update: /UPDATE\s+(\w+)/i,
1719
+ select: /SELECT.*\s+FROM\s+(\w+)/i,
1720
+ };
1721
+ let tableName = null;
1722
+ Object.keys(patterns).some((key) => {
1723
+ const pattern = patterns[key];
1724
+ const match = pattern.exec(sqlStatement);
1725
+ if (match) {
1726
+ tableName = match[1];
1727
+ return true; // Stop iterating through patterns
1728
+ }
1729
+ return false;
1730
+ });
1731
+ return tableName;
1732
+ }
1634
1733
  }
1635
1734
  utilsSQLite.UtilsSQLite = UtilsSQLite;
1636
1735
 
@@ -1861,7 +1960,7 @@ class UtilsJson {
1861
1960
  if (stmt.substring(0, 6).toUpperCase() === 'DELETE') {
1862
1961
  row = [];
1863
1962
  }
1864
- results = this.sqliteUtil.prepareRun(mDB, stmt, row, true);
1963
+ results = this.sqliteUtil.prepareRun(mDB, stmt, row, true, 'no');
1865
1964
  lastId = results.lastId;
1866
1965
  if (lastId < 0) {
1867
1966
  throw new Error(`${msg} lastId < 0`);
@@ -1893,8 +1992,7 @@ class UtilsJson {
1893
1992
  if (row.length != tColNames.length ||
1894
1993
  row.length === 0 ||
1895
1994
  tColNames.length === 0) {
1896
- throw new Error(`${msg} Table ${tableName} ` +
1897
- `values row ${j} not correct length`);
1995
+ throw new Error(`${msg} Table ${tableName} ` + `values row ${j} not correct length`);
1898
1996
  }
1899
1997
  try {
1900
1998
  const retisIdExists = this.isIdExists(mDB, tableName, tColNames[0], row[0]);
@@ -2521,8 +2619,7 @@ class ExportToJson {
2521
2619
  break;
2522
2620
  }
2523
2621
  default: {
2524
- errmsg =
2525
- `${msg} expMode ${sqlObj.mode} not defined`;
2622
+ errmsg = `${msg} expMode ${sqlObj.mode} not defined`;
2526
2623
  break;
2527
2624
  }
2528
2625
  }
@@ -2566,7 +2663,7 @@ class ExportToJson {
2566
2663
  }
2567
2664
  }
2568
2665
  getLastExportDate(mDb) {
2569
- const msg = "GetLastExportDate";
2666
+ const msg = 'GetLastExportDate';
2570
2667
  let retDate = -1;
2571
2668
  try {
2572
2669
  // get the last sync date
@@ -2589,7 +2686,7 @@ class ExportToJson {
2589
2686
  * @returns
2590
2687
  */
2591
2688
  setLastExportDate(mDb, lastExportedDate) {
2592
- const msg = "SetLastExportDate";
2689
+ const msg = 'SetLastExportDate';
2593
2690
  try {
2594
2691
  const isTable = this.jsonUtil.isTableExists(mDb, true, 'sync_table');
2595
2692
  if (!isTable) {
@@ -2597,7 +2694,7 @@ class ExportToJson {
2597
2694
  }
2598
2695
  const sDate = Math.round(new Date(lastExportedDate).getTime() / 1000);
2599
2696
  let stmt = '';
2600
- if ((this.getLastExportDate(mDb)) > 0) {
2697
+ if (this.getLastExportDate(mDb) > 0) {
2601
2698
  stmt = `UPDATE sync_table SET sync_date = ${sDate} WHERE id = 2;`;
2602
2699
  }
2603
2700
  else {
@@ -2619,7 +2716,7 @@ class ExportToJson {
2619
2716
  }
2620
2717
  }
2621
2718
  delExportedRows(mDb) {
2622
- const msg = "DelExportedRows";
2719
+ const msg = 'DelExportedRows';
2623
2720
  let lastExportDate;
2624
2721
  try {
2625
2722
  // check if synchronization table exists
@@ -2642,7 +2739,7 @@ class ExportToJson {
2642
2739
  // define the delete statement
2643
2740
  const delStmt = `DELETE FROM ${table}
2644
2741
  WHERE sql_deleted = 1 AND last_modified < ${lastExportDate};`;
2645
- const results = this.sqliteUtil.prepareRun(mDb, delStmt, [], true);
2742
+ const results = this.sqliteUtil.prepareRun(mDb, delStmt, [], true, 'no');
2646
2743
  if (results.lastId < 0) {
2647
2744
  throw new Error(`${msg} lastId < 0`);
2648
2745
  }
@@ -2681,7 +2778,7 @@ class ExportToJson {
2681
2778
  * @param mDb
2682
2779
  */
2683
2780
  getSyncDate(mDb) {
2684
- const msg = "GetSyncDate";
2781
+ const msg = 'GetSyncDate';
2685
2782
  let retDate = -1;
2686
2783
  // get the last sync date
2687
2784
  const stmt = `SELECT sync_date FROM sync_table WHERE id = ?;`;
@@ -3240,7 +3337,7 @@ class UtilsDrop {
3240
3337
  statements.push(stmt);
3241
3338
  }
3242
3339
  for (const stmt of statements) {
3243
- const results = this.sqliteUtil.prepareRun(db, stmt, [], false);
3340
+ const results = this.sqliteUtil.prepareRun(db, stmt, [], false, 'no');
3244
3341
  if (results.lastId < 0) {
3245
3342
  throw new Error(`${msg}: lastId < 0`);
3246
3343
  }
@@ -3268,7 +3365,7 @@ class UtilsDrop {
3268
3365
  // drop views
3269
3366
  this.dropElements(db, 'view');
3270
3367
  // vacuum the database
3271
- this.sqliteUtil.prepareRun(db, 'VACUUM;', [], false);
3368
+ this.sqliteUtil.prepareRun(db, 'VACUUM;', [], false, 'no');
3272
3369
  return;
3273
3370
  }
3274
3371
  catch (err) {
@@ -3512,7 +3609,7 @@ class UtilsSecret {
3512
3609
  throw new Error(`setEncryptSecret: passphrase already stored`);
3513
3610
  }
3514
3611
  else {
3515
- oldpassphrase = this.globalUtil != null ? this.globalUtil.secret : "";
3612
+ oldpassphrase = this.globalUtil != null ? this.globalUtil.secret : '';
3516
3613
  if (oldpassphrase.length <= 0) {
3517
3614
  throw new Error(`setEncryptSecret: globalUtil is null`);
3518
3615
  }
@@ -3547,7 +3644,7 @@ class UtilsSecret {
3547
3644
  oldpassphrase = this.globalUtil.secret;
3548
3645
  }
3549
3646
  // check if some databases were encrypted with the oldpassphrase
3550
- this.changeDatabaseSecret(oldpassphrase, "").then(() => {
3647
+ this.changeDatabaseSecret(oldpassphrase, '').then(() => {
3551
3648
  this.removePassphrase();
3552
3649
  });
3553
3650
  }
@@ -3590,12 +3687,12 @@ class UtilsSecret {
3590
3687
  const data = this.storage.getSync('userData');
3591
3688
  const keys = Object.keys(data);
3592
3689
  if (data == null || keys.length <= 0)
3593
- return "";
3690
+ return '';
3594
3691
  if (Object.keys(data).includes('passphrase')) {
3595
3692
  return data.passphrase;
3596
3693
  }
3597
3694
  else {
3598
- return "";
3695
+ return '';
3599
3696
  }
3600
3697
  }
3601
3698
  setPassphrase(passphrase) {
@@ -4039,7 +4136,7 @@ class Database {
4039
4136
  * @param values: string[]
4040
4137
  * @returns Promise<{changes:number, lastId:number}>
4041
4138
  */
4042
- runSQL(statement, values, transaction) {
4139
+ runSQL(statement, values, transaction, returnMode) {
4043
4140
  this.ensureDatabaseIsOpen();
4044
4141
  try {
4045
4142
  // start a transaction
@@ -4053,7 +4150,7 @@ class Database {
4053
4150
  throw new Error(`RunSQL: ${err}`);
4054
4151
  }
4055
4152
  try {
4056
- const results = this.sqliteUtil.prepareRun(this.database, statement, values, false);
4153
+ const results = this.sqliteUtil.prepareRun(this.database, statement, values, false, returnMode);
4057
4154
  if (results.lastId < 0) {
4058
4155
  if (transaction) {
4059
4156
  this.sqliteUtil.rollbackTransaction(this.database, this._isDbOpen);
@@ -4078,7 +4175,7 @@ class Database {
4078
4175
  * @param set: any[]
4079
4176
  * @returns Promise<{changes:number, lastId:number}>
4080
4177
  */
4081
- execSet(set, transaction) {
4178
+ execSet(set, transaction, returnMode) {
4082
4179
  this.ensureDatabaseIsOpen();
4083
4180
  let results = { changes: 0, lastId: -1 };
4084
4181
  try {
@@ -4093,7 +4190,7 @@ class Database {
4093
4190
  throw new Error(`ExecSet: ${err}`);
4094
4191
  }
4095
4192
  try {
4096
- results = this.sqliteUtil.executeSet(this.database, set, false);
4193
+ results = this.sqliteUtil.executeSet(this.database, set, false, returnMode);
4097
4194
  if (transaction) {
4098
4195
  this.sqliteUtil.commitTransaction(this.database, this._isDbOpen);
4099
4196
  }
@@ -4389,6 +4486,7 @@ class CapacitorSQLite {
4389
4486
  const setOfStatements = this.getOptionValue(options, 'set');
4390
4487
  const transaction = this.getOptionValue(options, 'transaction', true);
4391
4488
  const readonly = options.readonly ? options.readonly : false;
4489
+ const returnMode = options.returnMode ? options.returnMode : 'no';
4392
4490
  const connName = 'RW_' + dbName;
4393
4491
  const database = this.getDatabaseConnectionOrThrowError(connName);
4394
4492
  for (const sStmt of setOfStatements) {
@@ -4402,7 +4500,7 @@ class CapacitorSQLite {
4402
4500
  throw new Error(`ExecuteSet failed: ${msg}`);
4403
4501
  }
4404
4502
  try {
4405
- const execSetResult = database.execSet(setOfStatements, transaction);
4503
+ const execSetResult = database.execSet(setOfStatements, transaction, returnMode);
4406
4504
  if (execSetResult.lastId < 0) {
4407
4505
  throw new Error(`ExecuteSet failed changes <0`);
4408
4506
  }
@@ -4425,6 +4523,7 @@ class CapacitorSQLite {
4425
4523
  const values = this.getOptionValue(options, 'values', []);
4426
4524
  const transaction = this.getOptionValue(options, 'transaction', true);
4427
4525
  const readonly = options.readonly ? options.readonly : false;
4526
+ const returnMode = options.returnMode ? options.returnMode : 'no';
4428
4527
  const connName = 'RW_' + dbName;
4429
4528
  const database = this.getDatabaseConnectionOrThrowError(connName);
4430
4529
  if (database.isDBOpen()) {
@@ -4433,7 +4532,7 @@ class CapacitorSQLite {
4433
4532
  throw new Error(`Run failed: ${msg}`);
4434
4533
  }
4435
4534
  try {
4436
- const runResult = database.runSQL(statement, values, transaction);
4535
+ const runResult = database.runSQL(statement, values, transaction, returnMode);
4437
4536
  return { changes: runResult };
4438
4537
  }
4439
4538
  catch (err) {
@@ -4859,7 +4958,7 @@ class CapacitorSQLite {
4859
4958
  if (!isEncrypt) {
4860
4959
  throw new Error(`setEncryptionSecret: Not available electronIsEncryption = false in capacitor.config.ts`);
4861
4960
  }
4862
- const passphrase = options.passphrase ? options.passphrase : "";
4961
+ const passphrase = options.passphrase ? options.passphrase : '';
4863
4962
  if (passphrase.length <= 0) {
4864
4963
  throw new Error(`setEncryptionSecret: You must give a passphrase`);
4865
4964
  }
@@ -4883,14 +4982,14 @@ class CapacitorSQLite {
4883
4982
  throw new Error(`changeEncryptionSecret: Not available electronIsEncryption = false in capacitor.config.ts`);
4884
4983
  }
4885
4984
  const oldsecret = this.secretUtil.getPassphrase();
4886
- const oldpassphrase = options.oldpassphrase ? options.oldpassphrase : "";
4985
+ const oldpassphrase = options.oldpassphrase ? options.oldpassphrase : '';
4887
4986
  if (oldpassphrase.length <= 0) {
4888
4987
  throw new Error(`changeEncryptionSecret: You must give the oldpassphrase`);
4889
4988
  }
4890
4989
  if (oldpassphrase !== oldsecret) {
4891
4990
  throw new Error(`changeEncryptionSecret: the given oldpassphrase is wrong`);
4892
4991
  }
4893
- const passphrase = options.passphrase ? options.passphrase : "";
4992
+ const passphrase = options.passphrase ? options.passphrase : '';
4894
4993
  if (passphrase.length <= 0) {
4895
4994
  throw new Error(`changetEncryptionSecret: You must give a passphrase`);
4896
4995
  }
@@ -4938,7 +5037,7 @@ class CapacitorSQLite {
4938
5037
  if (!isEncrypt) {
4939
5038
  throw new Error(`checkEncryptionSecret: Not available electronIsEncryption = false in capacitor.config.ts`);
4940
5039
  }
4941
- const passphrase = options.passphrase ? options.passphrase : "";
5040
+ const passphrase = options.passphrase ? options.passphrase : '';
4942
5041
  if (passphrase.length <= 0) {
4943
5042
  throw new Error(`checkEncryptionSecret: You must give a passphrase`);
4944
5043
  }