@capacitor-community/sqlite 5.0.5-1 → 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 +197 -125
  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
@@ -30,7 +30,6 @@ import com.getcapacitor.community.database.sqlite.SQLite.UtilsSQLCipher;
30
30
  import com.getcapacitor.community.database.sqlite.SQLite.UtilsSQLite;
31
31
  import com.getcapacitor.community.database.sqlite.SQLite.UtilsSecret;
32
32
  import java.io.File;
33
- import java.nio.ByteBuffer;
34
33
  import java.security.KeyStore;
35
34
  import java.util.ArrayList;
36
35
  import java.util.Collections;
@@ -40,8 +39,8 @@ import java.util.HashMap;
40
39
  import java.util.HashSet;
41
40
  import java.util.Hashtable;
42
41
  import java.util.Map;
42
+ import java.util.Objects;
43
43
  import java.util.Set;
44
- import org.json.JSONException;
45
44
  import org.json.JSONObject;
46
45
 
47
46
  public class CapacitorSQLite {
@@ -61,9 +60,8 @@ public class CapacitorSQLite {
61
60
  private SharedPreferences sharedPreferences = null;
62
61
  private MasterKey masterKeyAlias;
63
62
  private BiometricManager biometricManager;
64
- private final SqliteConfig config;
65
- private Boolean isEncryption = true;
66
- private Boolean biometricAuth = false;
63
+ private final Boolean isEncryption;
64
+ private final Boolean biometricAuth;
67
65
  private final String biometricTitle;
68
66
  private final String biometricSubTitle;
69
67
  private final int VALIDITY_DURATION = 5;
@@ -74,11 +72,10 @@ public class CapacitorSQLite {
74
72
  public CapacitorSQLite(Context context, SqliteConfig config) throws Exception {
75
73
  this.context = context;
76
74
  this.call = call;
77
- this.config = config;
78
- this.isEncryption = this.config.getIsEncryption();
79
- this.biometricAuth = this.config.getBiometricAuth();
80
- this.biometricTitle = this.config.getBiometricTitle();
81
- this.biometricSubTitle = this.config.getBiometricSubTitle();
75
+ this.isEncryption = config.getIsEncryption();
76
+ this.biometricAuth = config.getBiometricAuth();
77
+ this.biometricTitle = config.getBiometricTitle();
78
+ this.biometricSubTitle = config.getBiometricSubTitle();
82
79
  try {
83
80
  if (isEncryption) {
84
81
  // create or retrieve masterkey from Android keystore
@@ -104,7 +101,6 @@ public class CapacitorSQLite {
104
101
  }
105
102
  setSharedPreferences();
106
103
  notifyBiometricEvent(true, null);
107
- return;
108
104
  } catch (Exception e) {
109
105
  String input = e.getMessage();
110
106
  Log.e("MY_APP_TAG", input);
@@ -139,7 +135,7 @@ public class CapacitorSQLite {
139
135
  }
140
136
 
141
137
  private void notifyBiometricEvent(Boolean ret, String msg) {
142
- Map<String, Object> info = new HashMap<String, Object>() {
138
+ Map<String, Object> info = new HashMap<>() {
143
139
  {
144
140
  put("result", ret);
145
141
  put("message", msg);
@@ -169,15 +165,15 @@ public class CapacitorSQLite {
169
165
  /**
170
166
  * Echo
171
167
  *
172
- * @param value
173
- * @return
168
+ * @param value string to echo
169
+ * @return string to echo
174
170
  */
175
171
  public String echo(String value) {
176
172
  return value;
177
173
  }
178
174
 
179
175
  public Boolean isSecretStored() throws Exception {
180
- Boolean ret = false;
176
+ boolean ret = false;
181
177
  if (isEncryption) {
182
178
  try {
183
179
  String secret = uSecret.getPassphrase();
@@ -194,8 +190,8 @@ public class CapacitorSQLite {
194
190
  /**
195
191
  * SetEncryptionSecret
196
192
  *
197
- * @param passphrase
198
- * @throws Exception
193
+ * @param passphrase passphrase
194
+ * @throws Exception message
199
195
  */
200
196
  public void setEncryptionSecret(String passphrase) throws Exception {
201
197
  if (isEncryption) {
@@ -215,9 +211,9 @@ public class CapacitorSQLite {
215
211
  /**
216
212
  * ChangeEncryptionSecret
217
213
  *
218
- * @param passphrase
219
- * @param oldPassphrase
220
- * @throws Exception
214
+ * @param passphrase new passphrase
215
+ * @param oldPassphrase old passphrase
216
+ * @throws Exception message
221
217
  */
222
218
  public void changeEncryptionSecret(PluginCall call, String passphrase, String oldPassphrase) throws Exception {
223
219
  this.call = call;
@@ -233,7 +229,6 @@ public class CapacitorSQLite {
233
229
  // change encryption secret
234
230
  uSecret.changeEncryptionSecret(passphrase, oldPassphrase);
235
231
  rHandler.retResult(call, null, null);
236
- return;
237
232
  } catch (Exception e) {
238
233
  String input = e.getMessage();
239
234
  Log.e("MY_APP_TAG", input);
@@ -271,7 +266,7 @@ public class CapacitorSQLite {
271
266
 
272
267
  /**
273
268
  * ClearEncryptionSecret
274
- * @throws Exception
269
+ * @throws Exception message
275
270
  */
276
271
  public void clearEncryptionSecret() throws Exception {
277
272
  if (isEncryption) {
@@ -291,8 +286,8 @@ public class CapacitorSQLite {
291
286
  /**
292
287
  * CheckEncryptionSecret
293
288
  *
294
- * @param passphrase
295
- * @throws Exception
289
+ * @param passphrase secret phrase for encryption
290
+ * @throws Exception message
296
291
  */
297
292
  public Boolean checkEncryptionSecret(String passphrase) throws Exception {
298
293
  if (isEncryption) {
@@ -300,8 +295,7 @@ public class CapacitorSQLite {
300
295
  // close all connections
301
296
  closeAllConnections();
302
297
  // set encryption secret
303
- Boolean res = uSecret.checkEncryptionSecret(passphrase);
304
- return res;
298
+ return uSecret.checkEncryptionSecret(passphrase);
305
299
  } catch (Exception e) {
306
300
  throw new Exception(e.getMessage());
307
301
  }
@@ -312,8 +306,7 @@ public class CapacitorSQLite {
312
306
 
313
307
  public String getNCDatabasePath(String folderPath, String database) throws Exception {
314
308
  try {
315
- String databasePath = uNCDatabase.getNCDatabasePath(context, folderPath, database);
316
- return databasePath;
309
+ return uNCDatabase.getNCDatabasePath(context, folderPath, database);
317
310
  } catch (Exception e) {
318
311
  throw new Exception(e.getMessage());
319
312
  }
@@ -322,12 +315,12 @@ public class CapacitorSQLite {
322
315
  /**
323
316
  * CreateConnection
324
317
  *
325
- * @param dbName
326
- * @param encrypted
327
- * @param mode
328
- * @param version
329
- * @param vUpgObject
330
- * @throws Exception
318
+ * @param dbName database name
319
+ * @param encrypted boolean
320
+ * @param mode "no-encryption", "secret", "encryption"
321
+ * @param version database version
322
+ * @param vUpgObject upgrade Object
323
+ * @throws Exception message
331
324
  */
332
325
  public void createConnection(
333
326
  String dbName,
@@ -360,13 +353,7 @@ public class CapacitorSQLite {
360
353
  sharedPreferences,
361
354
  readonly
362
355
  );
363
- if (db != null) {
364
- dbDict.put(connName, db);
365
- return;
366
- } else {
367
- String msg = "db is null";
368
- throw new Exception(msg);
369
- }
356
+ dbDict.put(connName, db);
370
357
  } catch (Exception e) {
371
358
  throw new Exception(e.getMessage());
372
359
  }
@@ -375,9 +362,9 @@ public class CapacitorSQLite {
375
362
  /**
376
363
  * CreateNCConnection
377
364
  *
378
- * @param dbPath
379
- * @param version
380
- * @throws Exception
365
+ * @param dbPath database path
366
+ * @param version database version
367
+ * @throws Exception message
381
368
  */
382
369
  public void createNCConnection(String dbPath, int version) throws Exception {
383
370
  // check if connection already exists
@@ -404,13 +391,7 @@ public class CapacitorSQLite {
404
391
  sharedPreferences,
405
392
  true
406
393
  );
407
- if (db != null) {
408
- dbDict.put(connName, db);
409
- return;
410
- } else {
411
- String msg = "db is null";
412
- throw new Exception(msg);
413
- }
394
+ dbDict.put(connName, db);
414
395
  } catch (Exception e) {
415
396
  throw new Exception(e.getMessage());
416
397
  }
@@ -419,8 +400,8 @@ public class CapacitorSQLite {
419
400
  /**
420
401
  * Open
421
402
  *
422
- * @param dbName
423
- * @throws Exception
403
+ * @param dbName database name
404
+ * @throws Exception message
424
405
  */
425
406
  public void open(String dbName, Boolean readonly) throws Exception {
426
407
  dbName = getDatabaseName(dbName);
@@ -429,7 +410,6 @@ public class CapacitorSQLite {
429
410
  if (db != null) {
430
411
  try {
431
412
  db.open();
432
- return;
433
413
  } catch (Exception e) {
434
414
  throw new Exception(e.getMessage());
435
415
  }
@@ -442,8 +422,8 @@ public class CapacitorSQLite {
442
422
  /**
443
423
  * Close
444
424
  *
445
- * @param dbName
446
- * @throws Exception
425
+ * @param dbName database name
426
+ * @throws Exception message
447
427
  */
448
428
  public void close(String dbName, Boolean readonly) throws Exception {
449
429
  dbName = getDatabaseName(dbName);
@@ -454,7 +434,6 @@ public class CapacitorSQLite {
454
434
  if (!db.inTransaction()) {
455
435
  try {
456
436
  db.close();
457
- return;
458
437
  } catch (Exception e) {
459
438
  throw new Exception(e.getMessage());
460
439
  }
@@ -475,9 +454,9 @@ public class CapacitorSQLite {
475
454
  /**
476
455
  * GetUrl
477
456
  *
478
- * @param dbName
457
+ * @param dbName database name
479
458
  * @return String
480
- * @throws Exception
459
+ * @throws Exception message
481
460
  */
482
461
  public String getUrl(String dbName, Boolean readonly) throws Exception {
483
462
  dbName = getDatabaseName(dbName);
@@ -485,8 +464,7 @@ public class CapacitorSQLite {
485
464
  Database db = dbDict.get(connName);
486
465
  if (db != null) {
487
466
  try {
488
- String url = db.getUrl();
489
- return url;
467
+ return db.getUrl();
490
468
  } catch (Exception e) {
491
469
  throw new Exception(e.getMessage());
492
470
  }
@@ -499,9 +477,9 @@ public class CapacitorSQLite {
499
477
  /**
500
478
  * GetVersion
501
479
  *
502
- * @param dbName
480
+ * @param dbName database name
503
481
  * @return Integer
504
- * @throws Exception
482
+ * @throws Exception message
505
483
  */
506
484
  public Integer getVersion(String dbName, Boolean readonly) throws Exception {
507
485
  dbName = getDatabaseName(dbName);
@@ -509,8 +487,7 @@ public class CapacitorSQLite {
509
487
  Database db = dbDict.get(connName);
510
488
  if (db != null) {
511
489
  try {
512
- Integer version = db.getVersion();
513
- return version;
490
+ return db.getVersion();
514
491
  } catch (Exception e) {
515
492
  throw new Exception(e.getMessage());
516
493
  }
@@ -523,8 +500,8 @@ public class CapacitorSQLite {
523
500
  /**
524
501
  * CloseNCConnection
525
502
  *
526
- * @param dbPath
527
- * @throws Exception
503
+ * @param dbPath database path
504
+ * @throws Exception message
528
505
  */
529
506
  public void closeNCConnection(String dbPath) throws Exception {
530
507
  String connName = "RO_" + dbPath;
@@ -538,7 +515,6 @@ public class CapacitorSQLite {
538
515
  }
539
516
  }
540
517
  dbDict.remove(connName);
541
- return;
542
518
  } else {
543
519
  String msg = "No available connection for database " + dbPath;
544
520
  throw new Exception(msg);
@@ -548,8 +524,8 @@ public class CapacitorSQLite {
548
524
  /**
549
525
  * CloseConnection
550
526
  *
551
- * @param dbName
552
- * @throws Exception
527
+ * @param dbName database name
528
+ * @throws Exception message
553
529
  */
554
530
  public void closeConnection(String dbName, Boolean readonly) throws Exception {
555
531
  dbName = getDatabaseName(dbName);
@@ -564,7 +540,6 @@ public class CapacitorSQLite {
564
540
  }
565
541
  }
566
542
  dbDict.remove(connName);
567
- return;
568
543
  } else {
569
544
  String msg = "No available connection for database " + dbName;
570
545
  throw new Exception(msg);
@@ -580,14 +555,13 @@ public class CapacitorSQLite {
580
555
  }
581
556
 
582
557
  public Boolean checkConnectionsConsistency(JSArray dbNames, JSArray openModes) throws Exception {
583
- Set<String> keys = new HashSet<String>(Collections.list(dbDict.keys()));
584
- String msg = "All Native Connections released";
558
+ Set<String> keys = new HashSet<>(Collections.list(dbDict.keys()));
585
559
  JSArray nameDBs = new JSArray();
586
- for (Integer i = 0; i < dbNames.length(); i++) {
560
+ for (int i = 0; i < dbNames.length(); i++) {
587
561
  String name = openModes.getString(i) + "_" + dbNames.getString(i);
588
562
  nameDBs.put(name);
589
563
  }
590
- Set<String> conns = new HashSet<String>(uSqlite.stringJSArrayToArrayList(nameDBs));
564
+ Set<String> conns = new HashSet<>(uSqlite.stringJSArrayToArrayList(nameDBs));
591
565
  try {
592
566
  if (conns.size() == 0) {
593
567
  closeAllConnections();
@@ -605,11 +579,11 @@ public class CapacitorSQLite {
605
579
  }
606
580
  }
607
581
  }
608
- keys = new HashSet<String>(Collections.list(dbDict.keys()));
582
+ keys = new HashSet<>(Collections.list(dbDict.keys()));
609
583
  if (keys.size() == conns.size()) {
610
- Set<String> symmetricDiff = new HashSet<String>(keys);
584
+ Set<String> symmetricDiff = new HashSet<>(keys);
611
585
  symmetricDiff.addAll(conns);
612
- Set<String> tmp = new HashSet<String>(keys);
586
+ Set<String> tmp = new HashSet<>(keys);
613
587
  tmp.retainAll(conns);
614
588
  symmetricDiff.removeAll(tmp);
615
589
  if (symmetricDiff.size() == 0) {
@@ -631,9 +605,8 @@ public class CapacitorSQLite {
631
605
  /**
632
606
  * IsDatabase
633
607
  *
634
- * @param dbName
608
+ * @param dbName database name
635
609
  * @return Boolean
636
- * @throws Exception
637
610
  */
638
611
  public Boolean isDatabase(String dbName) {
639
612
  dbName = getDatabaseName(dbName);
@@ -643,9 +616,9 @@ public class CapacitorSQLite {
643
616
  /**
644
617
  * IsDatabaseEncrypted
645
618
  *
646
- * @param dbName
619
+ * @param dbName database name
647
620
  * @return Boolean
648
- * @throws Exception
621
+ * @throws Exception message
649
622
  */
650
623
  public Boolean isDatabaseEncrypted(String dbName) throws Exception {
651
624
  dbName = getDatabaseName(dbName);
@@ -667,9 +640,8 @@ public class CapacitorSQLite {
667
640
  /**
668
641
  * IsNCDatabase
669
642
  *
670
- * @param dbPath
643
+ * @param dbPath database path
671
644
  * @return Boolean
672
- * @throws Exception
673
645
  */
674
646
  public Boolean isNCDatabase(String dbPath) {
675
647
  return uFile.isPathExists(dbPath);
@@ -678,17 +650,16 @@ public class CapacitorSQLite {
678
650
  /**
679
651
  * IsTableExists
680
652
  *
681
- * @param dbName
682
- * @param tableName
683
- * @throws Exception
653
+ * @param dbName database name
654
+ * @param tableName table name
655
+ * @throws Exception message
684
656
  */
685
657
  public Boolean isTableExists(String dbName, String tableName, Boolean readonly) throws Exception {
686
658
  dbName = getDatabaseName(dbName);
687
659
  String connName = readonly ? "RO_" + dbName : "RW_" + dbName;
688
660
  Database db = dbDict.get(connName);
689
661
  if (db != null) {
690
- boolean res = uJson.isTableExists(db, tableName);
691
- return res;
662
+ return uJson.isTableExists(db, tableName);
692
663
  } else {
693
664
  String msg = "No available connection for database " + dbName;
694
665
  throw new Exception(msg);
@@ -698,8 +669,8 @@ public class CapacitorSQLite {
698
669
  /**
699
670
  * GetDatabaseList
700
671
  *
701
- * @return JSArray
702
- * @throws Exception
672
+ * @return JSArray database list
673
+ * @throws Exception message
703
674
  */
704
675
  public JSArray getDatabaseList() throws Exception {
705
676
  String[] listFiles = uFile.getListOfFiles(context);
@@ -718,8 +689,8 @@ public class CapacitorSQLite {
718
689
  /**
719
690
  * GetMigratableDbList
720
691
  *
721
- * @return JSArray
722
- * @throws Exception
692
+ * @return JSArray database list
693
+ * @throws Exception message
723
694
  */
724
695
  public JSArray getMigratableDbList(String folderPath) throws Exception {
725
696
  String[] listFiles = uMigrate.getMigratableList(context, folderPath);
@@ -738,28 +709,26 @@ public class CapacitorSQLite {
738
709
  /**
739
710
  * AddSQLiteSuffix
740
711
  *
741
- * @param folderPath
742
- * @throws Exception
712
+ * @param folderPath folder path
713
+ * @throws Exception message
743
714
  */
744
715
  public void addSQLiteSuffix(String folderPath, JSArray dbList) throws Exception {
745
716
  try {
746
717
  ArrayList<String> mDbList = uSqlite.stringJSArrayToArrayList(dbList);
747
718
  uMigrate.addSQLiteSuffix(context, folderPath, mDbList);
748
- return;
749
719
  } catch (Exception e) {
750
720
  throw new Exception(e.getMessage());
751
721
  }
752
722
  }
753
723
 
754
724
  /**
755
- * @param folderPath
756
- * @throws Exception
725
+ * @param folderPath folder path
726
+ * @throws Exception message
757
727
  */
758
728
  public void deleteOldDatabases(String folderPath, JSArray dbList) throws Exception {
759
729
  try {
760
730
  ArrayList<String> mDbList = uSqlite.stringJSArrayToArrayList(dbList);
761
731
  uMigrate.deleteOldDatabases(context, folderPath, mDbList);
762
- return;
763
732
  } catch (Exception e) {
764
733
  throw new Exception(e.getMessage());
765
734
  }
@@ -767,14 +736,13 @@ public class CapacitorSQLite {
767
736
 
768
737
  /**
769
738
  *
770
- * @param folderPath
771
- * @throws Exception
739
+ * @param folderPath folder path
740
+ * @throws Exception message
772
741
  */
773
742
  public void moveDatabasesAndAddSuffix(String folderPath, JSArray dbList) throws Exception {
774
743
  try {
775
744
  ArrayList<String> mDbList = uSqlite.stringJSArrayToArrayList(dbList);
776
745
  uMigrate.moveDatabasesAndAddSuffix(context, folderPath, mDbList);
777
- return;
778
746
  } catch (Exception e) {
779
747
  throw new Exception(e.getMessage());
780
748
  }
@@ -783,10 +751,10 @@ public class CapacitorSQLite {
783
751
  /**
784
752
  * Execute
785
753
  *
786
- * @param dbName
787
- * @param statements
788
- * @return
789
- * @throws Exception
754
+ * @param dbName Database name
755
+ * @param statements a bench of statement
756
+ * @return JSObject changes
757
+ * @throws Exception message
790
758
  */
791
759
  public JSObject execute(String dbName, String statements, Boolean transaction, Boolean readonly) throws Exception {
792
760
  dbName = getDatabaseName(dbName);
@@ -800,8 +768,7 @@ public class CapacitorSQLite {
800
768
  // convert string in string[]
801
769
  String[] sqlCmdArray = uSqlite.getStatementsArray(statements);
802
770
  try {
803
- JSObject res = db.execute(sqlCmdArray, transaction);
804
- return res;
771
+ return db.execute(sqlCmdArray, transaction);
805
772
  } catch (Exception e) {
806
773
  throw new Exception(e.getMessage());
807
774
  }
@@ -818,12 +785,12 @@ public class CapacitorSQLite {
818
785
  /**
819
786
  * ExecuteSet
820
787
  *
821
- * @param dbName
822
- * @param set
823
- * @return
824
- * @throws Exception
788
+ * @param dbName database name
789
+ * @param set Set containing statements and values
790
+ * @return JSObject changes, lastId, values when RETURNING
791
+ * @throws Exception message
825
792
  */
826
- public JSObject executeSet(String dbName, JSArray set, Boolean transaction, Boolean readonly) throws Exception {
793
+ public JSObject executeSet(String dbName, JSArray set, Boolean transaction, Boolean readonly, String returnMode) throws Exception {
827
794
  dbName = getDatabaseName(dbName);
828
795
  String connName = "RW_" + dbName;
829
796
  Database db = dbDict.get(connName);
@@ -833,8 +800,7 @@ public class CapacitorSQLite {
833
800
  }
834
801
  if (!db.isNCDB() && db.isOpen()) {
835
802
  try {
836
- JSObject res = db.executeSet(set, transaction);
837
- return res;
803
+ return db.executeSet(set, transaction, returnMode);
838
804
  } catch (Exception e) {
839
805
  throw new Exception(e.getMessage());
840
806
  }
@@ -851,13 +817,14 @@ public class CapacitorSQLite {
851
817
  /**
852
818
  * Run
853
819
  *
854
- * @param dbName
855
- * @param statement
856
- * @param values
857
- * @return
858
- * @throws Exception
820
+ * @param dbName Database name
821
+ * @param statement SQLite statement
822
+ * @param values SQLite values if any
823
+ * @return JSObject changes, lastId, values when RETURNING
824
+ * @throws Exception message
859
825
  */
860
- public JSObject run(String dbName, String statement, JSArray values, Boolean transaction, Boolean readonly) throws Exception {
826
+ public JSObject run(String dbName, String statement, JSArray values, Boolean transaction, Boolean readonly, String returnMode)
827
+ throws Exception {
861
828
  JSObject res;
862
829
  dbName = getDatabaseName(dbName);
863
830
  String connName = "RW_" + dbName;
@@ -869,17 +836,16 @@ public class CapacitorSQLite {
869
836
  if (!db.isNCDB() && db.isOpen()) {
870
837
  if (values.length() > 0) {
871
838
  try {
839
+ // returnMode = "no";
872
840
  ArrayList<Object> arrValues = uSqlite.objectJSArrayToArrayList(values);
873
- res = db.runSQL(statement, arrValues, transaction);
841
+ res = db.runSQL(statement, arrValues, transaction, returnMode);
874
842
  return res;
875
- } catch (JSONException e) {
876
- throw new Exception(e.getMessage());
877
843
  } catch (Exception e) {
878
844
  throw new Exception(e.getMessage());
879
845
  }
880
846
  } else {
881
847
  try {
882
- res = db.runSQL(statement, null, transaction);
848
+ res = db.runSQL(statement, null, transaction, returnMode);
883
849
  return res;
884
850
  } catch (Exception e) {
885
851
  throw new Exception(e.getMessage());
@@ -898,11 +864,11 @@ public class CapacitorSQLite {
898
864
  /**
899
865
  * Query
900
866
  *
901
- * @param dbName
902
- * @param statement
903
- * @param values
904
- * @return
905
- * @throws Exception
867
+ * @param dbName Database name
868
+ * @param statement SQLite statement
869
+ * @param values SQLite values if any
870
+ * @return JSArray
871
+ * @throws Exception message
906
872
  */
907
873
  public JSArray query(String dbName, String statement, JSArray values, Boolean readonly) throws Exception {
908
874
  JSArray res;
@@ -916,14 +882,12 @@ public class CapacitorSQLite {
916
882
  ArrayList<Object> arrValues = uSqlite.objectJSArrayToArrayList(values);
917
883
  res = db.selectSQL(statement, arrValues);
918
884
  return res;
919
- } catch (JSONException e) {
920
- throw new Exception(e.getMessage());
921
885
  } catch (Exception e) {
922
886
  throw new Exception(e.getMessage());
923
887
  }
924
888
  } else {
925
889
  try {
926
- res = db.selectSQL(statement, new ArrayList<Object>());
890
+ res = db.selectSQL(statement, new ArrayList<>());
927
891
  return res;
928
892
  } catch (Exception e) {
929
893
  throw new Exception(e.getMessage());
@@ -975,8 +939,7 @@ public class CapacitorSQLite {
975
939
  String connName = readonly ? "RO_" + dbName : "RW_" + dbName;
976
940
  Database db = dbDict.get(connName);
977
941
  if (db != null) {
978
- Boolean isOpen = db.isOpen();
979
- return isOpen;
942
+ return db.isOpen();
980
943
  } else {
981
944
  String msg = "No available connection for database " + dbName;
982
945
  throw new Exception(msg);
@@ -993,7 +956,6 @@ public class CapacitorSQLite {
993
956
  }
994
957
  try {
995
958
  db.deleteDB(dbName + "SQLite.db");
996
- return;
997
959
  } catch (Exception e) {
998
960
  throw new Exception(e.getMessage());
999
961
  }
@@ -1016,8 +978,7 @@ public class CapacitorSQLite {
1016
978
  String msg = "CreateSyncTable: db not opened";
1017
979
  throw new Exception(msg);
1018
980
  }
1019
- JSObject res = db.createSyncTable();
1020
- return res;
981
+ return db.createSyncTable();
1021
982
  } catch (Exception e) {
1022
983
  throw new Exception(e.getMessage());
1023
984
  }
@@ -1041,7 +1002,6 @@ public class CapacitorSQLite {
1041
1002
  throw new Exception(msg);
1042
1003
  }
1043
1004
  db.setSyncDate(syncDate);
1044
- return;
1045
1005
  } catch (Exception e) {
1046
1006
  throw new Exception(e.getMessage());
1047
1007
  }
@@ -1061,8 +1021,7 @@ public class CapacitorSQLite {
1061
1021
  String msg = "GetSyncDate: db not opened";
1062
1022
  throw new Exception(msg);
1063
1023
  }
1064
- long syncDate = db.getSyncDate();
1065
- return syncDate;
1024
+ return db.getSyncDate();
1066
1025
  } catch (Exception e) {
1067
1026
  throw new Exception(e.getMessage());
1068
1027
  }
@@ -1076,7 +1035,7 @@ public class CapacitorSQLite {
1076
1035
  Dictionary<Integer, JSONObject> upgDict = new Hashtable<>();
1077
1036
 
1078
1037
  for (int i = 0; i < upgrade.length(); i++) {
1079
- JSONObject upgObj = null;
1038
+ JSONObject upgObj;
1080
1039
  try {
1081
1040
  upgObj = (JSONObject) upgrade.get(i);
1082
1041
  if (upgObj == null || !upgObj.has("toVersion") || !upgObj.has("statements")) {
@@ -1103,8 +1062,7 @@ public class CapacitorSQLite {
1103
1062
  try {
1104
1063
  JSObject jsonObject = new JSObject(parsingData);
1105
1064
  JsonSQLite jsonSQL = new JsonSQLite();
1106
- Boolean isValid = jsonSQL.isJsonSQLite(jsonObject, isEncryption);
1107
- return isValid;
1065
+ return jsonSQL.isJsonSQLite(jsonObject, isEncryption);
1108
1066
  } catch (Exception e) {
1109
1067
  throw new Exception(e.getMessage());
1110
1068
  }
@@ -1114,13 +1072,13 @@ public class CapacitorSQLite {
1114
1072
  try {
1115
1073
  JSObject jsonObject = new JSObject(parsingData);
1116
1074
  JsonSQLite jsonSQL = new JsonSQLite();
1117
- Boolean isValid = jsonSQL.isJsonSQLite(jsonObject, isEncryption);
1075
+ boolean isValid = jsonSQL.isJsonSQLite(jsonObject, isEncryption);
1118
1076
  if (!isValid) {
1119
1077
  String msg = "Stringify Json Object not Valid";
1120
1078
  throw new Exception(msg);
1121
1079
  }
1122
1080
  String dbName = getDatabaseName(jsonSQL.getDatabase());
1123
- dbName = new StringBuilder(dbName).append("SQLite.db").toString();
1081
+ dbName = dbName + "SQLite.db";
1124
1082
  Integer dbVersion = jsonSQL.getVersion();
1125
1083
  String mode = jsonSQL.getMode();
1126
1084
  Boolean overwrite = jsonSQL.getOverwrite();
@@ -1161,7 +1119,7 @@ public class CapacitorSQLite {
1161
1119
  msg += "version lower than" + curVersion;
1162
1120
  throw new Exception(msg);
1163
1121
  }
1164
- if (curVersion == dbVersion) {
1122
+ if (curVersion.equals(dbVersion)) {
1165
1123
  JSObject result = new JSObject();
1166
1124
  result.put("changes", Integer.valueOf(0));
1167
1125
  return result;
@@ -1169,11 +1127,11 @@ public class CapacitorSQLite {
1169
1127
  }
1170
1128
  JSObject res = db.importFromJson(jsonSQL);
1171
1129
  db.close();
1172
- if (res.getInteger("changes") == Integer.valueOf(-1)) {
1130
+ if (!Objects.equals(res.getInteger("changes"), -1)) {
1131
+ return res;
1132
+ } else {
1173
1133
  String msg = "importFromJson: import JsonObject not successful";
1174
1134
  throw new Exception(msg);
1175
- } else {
1176
- return res;
1177
1135
  }
1178
1136
  }
1179
1137
  } catch (Exception e) {
@@ -1226,7 +1184,6 @@ public class CapacitorSQLite {
1226
1184
  throw new Exception(msg);
1227
1185
  }
1228
1186
  db.deleteExportedRows();
1229
- return;
1230
1187
  } catch (Exception e) {
1231
1188
  String msg = "DeleteExportedRows " + e.getMessage();
1232
1189
  throw new Exception(msg);
@@ -1241,7 +1198,6 @@ public class CapacitorSQLite {
1241
1198
  String msg = "copy failed : ";
1242
1199
  try {
1243
1200
  uFile.copyFromAssetsToDatabase(context, overwrite);
1244
- return;
1245
1201
  } catch (Exception e) {
1246
1202
  msg += e.getMessage();
1247
1203
  throw new Exception(msg);
@@ -1264,10 +1220,7 @@ public class CapacitorSQLite {
1264
1220
  Enumeration<String> connections = dbDict.keys();
1265
1221
  while (connections.hasMoreElements()) {
1266
1222
  String dbName = connections.nextElement();
1267
- Boolean readonly = false;
1268
- if (dbName.substring(0, 3).equals("RO_")) {
1269
- readonly = true;
1270
- }
1223
+ boolean readonly = dbName.startsWith("RO_");
1271
1224
  dbName = dbName.substring(3);
1272
1225
  closeConnection(dbName, readonly);
1273
1226
  }