@capacitor-community/sqlite 4.1.0-4 → 4.1.0-7

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 CHANGED
@@ -39,7 +39,7 @@ npx cap sync
39
39
  - [Issues](https://github.com/capacitor-community/sqlite/issues)
40
40
  - [Capacitor documentation](https://capacitorjs.com/docs/)
41
41
  - [Datatypes In SQLite Version 3](https://www.sqlite.org/datatype3.html)
42
-
42
+ - [IncrementalUpgradeDatabaseVersion](https://capacitorjs.com/docs/IncrementalUpgradeDatabaseVersion.md)
43
43
 
44
44
  ## Web Quirks
45
45
 
@@ -90,9 +90,12 @@ npm install --save-dev @types/sqlite3
90
90
 
91
91
  | Name | Android | iOS | Electron | Web |
92
92
  | :-------------------------- | :------ | :-- | :------- | :-- |
93
- | createConnection | ✅ | ✅ | ✅ | ✅ |
94
- | closeConnection | ✅ | ✅ | | |
95
- | isConnection | ✅ | ✅ | ✅ | ✅ |
93
+ | createConnection (ReadWrite)| ✅ | ✅ | ✅ | ✅ |
94
+ | createConnection (ReadOnly) | ✅ | ✅ | | | since 4.1.0-7
95
+ | closeConnection (ReadWrite) | ✅ | ✅ | ✅ | ✅ |
96
+ | closeConnection (ReadOnly) | ✅ | ✅ | ❌ | ❌ | since 4.1.0-7
97
+ | isConnection (ReadWrite) | ✅ | ✅ | ✅ | ✅ |
98
+ | isConnection (ReadOnly) | ✅ | ✅ | ❌ | ❌ | since 4.1.0-7
96
99
  | open (non-encrypted DB) | ✅ | ✅ | ✅ | ✅ |
97
100
  | open (encrypted DB) | ✅ | ✅ | ❌ | ❌ |
98
101
  | close | ✅ | ✅ | ✅ | ✅ |
@@ -111,7 +114,7 @@ npm install --save-dev @types/sqlite3
111
114
  | getSyncDate | ✅ | ✅ | ✅ | ✅ |
112
115
  | isJsonValid | ✅ | ✅ | ✅ | ✅ |
113
116
  | isDBExists | ✅ | ✅ | ✅ | ✅ |
114
- | addUpgradeStatement | ✅ | ✅ | ✅ | ✅ |
117
+ | addUpgradeStatement | ✅ | ✅ | ✅ | ✅ | Modified 4.1.0-6
115
118
  | copyFromAssets | ✅ | ✅ | ✅ | ✅ |
116
119
  | isDBOpen | ✅ | ✅ | ✅ | ✅ |
117
120
  | isDatabase | ✅ | ✅ | ✅ | ✅ |
@@ -2,14 +2,12 @@ package com.getcapacitor.community.database.sqlite;
2
2
 
3
3
  import android.content.Context;
4
4
  import android.content.SharedPreferences;
5
- import android.text.TextUtils;
6
5
  import android.util.Log;
7
6
  import android.widget.Toast;
8
7
  import androidx.biometric.BiometricManager;
9
8
  import androidx.biometric.BiometricPrompt;
10
9
  import androidx.security.crypto.EncryptedSharedPreferences;
11
10
  import androidx.security.crypto.MasterKey;
12
- import androidx.security.crypto.MasterKeys;
13
11
  import com.getcapacitor.JSArray;
14
12
  import com.getcapacitor.JSObject;
15
13
  import com.getcapacitor.PluginCall;
@@ -25,13 +23,8 @@ import com.getcapacitor.community.database.sqlite.SQLite.UtilsNCDatabase;
25
23
  import com.getcapacitor.community.database.sqlite.SQLite.UtilsSQLite;
26
24
  import com.getcapacitor.community.database.sqlite.SQLite.UtilsSecret;
27
25
  import java.io.File;
28
- import java.io.IOException;
29
- import java.nio.charset.Charset;
30
- import java.nio.charset.StandardCharsets;
31
- import java.security.GeneralSecurityException;
32
26
  import java.security.KeyStore;
33
27
  import java.util.ArrayList;
34
- import java.util.Arrays;
35
28
  import java.util.Collections;
36
29
  import java.util.Dictionary;
37
30
  import java.util.Enumeration;
@@ -40,32 +33,30 @@ import java.util.HashSet;
40
33
  import java.util.Hashtable;
41
34
  import java.util.Map;
42
35
  import java.util.Set;
43
- import javax.crypto.BadPaddingException;
44
- import javax.crypto.IllegalBlockSizeException;
45
36
  import org.json.JSONException;
46
37
  import org.json.JSONObject;
47
38
 
48
39
  public class CapacitorSQLite {
49
40
 
50
41
  private static final String TAG = CapacitorSQLite.class.getName();
51
- private Context context;
52
- private Dictionary<String, Database> dbDict = new Hashtable<>();
53
- private UtilsSQLite uSqlite = new UtilsSQLite();
54
- private UtilsFile uFile = new UtilsFile();
55
- private UtilsJson uJson = new UtilsJson();
56
- private UtilsMigrate uMigrate = new UtilsMigrate();
57
- private UtilsNCDatabase uNCDatabase = new UtilsNCDatabase();
42
+ private final Context context;
43
+ private final Dictionary<String, Database> dbDict = new Hashtable<>();
44
+ private final UtilsSQLite uSqlite = new UtilsSQLite();
45
+ private final UtilsFile uFile = new UtilsFile();
46
+ private final UtilsJson uJson = new UtilsJson();
47
+ private final UtilsMigrate uMigrate = new UtilsMigrate();
48
+ private final UtilsNCDatabase uNCDatabase = new UtilsNCDatabase();
58
49
  private UtilsSecret uSecret;
59
50
  private SharedPreferences sharedPreferences = null;
60
51
  private MasterKey masterKeyAlias;
61
52
  private BiometricManager biometricManager;
62
- private SqliteConfig config;
53
+ private final SqliteConfig config;
63
54
  private Boolean isEncryption = true;
64
55
  private Boolean biometricAuth = false;
65
- private String biometricTitle;
66
- private String biometricSubTitle;
67
- private int VALIDITY_DURATION = 5;
68
- private RetHandler rHandler = new RetHandler();
56
+ private final String biometricTitle;
57
+ private final String biometricSubTitle;
58
+ private final int VALIDITY_DURATION = 5;
59
+ private final RetHandler rHandler = new RetHandler();
69
60
  private PluginCall call;
70
61
 
71
62
  public CapacitorSQLite(Context context, SqliteConfig config) throws Exception {
@@ -165,6 +156,7 @@ public class CapacitorSQLite {
165
156
 
166
157
  /**
167
158
  * Echo
159
+ *
168
160
  * @param value
169
161
  * @return
170
162
  */
@@ -189,6 +181,7 @@ public class CapacitorSQLite {
189
181
 
190
182
  /**
191
183
  * SetEncryptionSecret
184
+ *
192
185
  * @param passphrase
193
186
  * @throws Exception
194
187
  */
@@ -209,6 +202,7 @@ public class CapacitorSQLite {
209
202
 
210
203
  /**
211
204
  * ChangeEncryptionSecret
205
+ *
212
206
  * @param passphrase
213
207
  * @param oldPassphrase
214
208
  * @throws Exception
@@ -293,6 +287,7 @@ public class CapacitorSQLite {
293
287
 
294
288
  /**
295
289
  * CreateConnection
290
+ *
296
291
  * @param dbName
297
292
  * @param encrypted
298
293
  * @param mode
@@ -300,11 +295,18 @@ public class CapacitorSQLite {
300
295
  * @param vUpgObject
301
296
  * @throws Exception
302
297
  */
303
- public void createConnection(String dbName, boolean encrypted, String mode, int version, Dictionary<Integer, JSONObject> vUpgObject)
304
- throws Exception {
298
+ public void createConnection(
299
+ String dbName,
300
+ boolean encrypted,
301
+ String mode,
302
+ int version,
303
+ Dictionary<Integer, JSONObject> vUpgObject,
304
+ Boolean readonly
305
+ ) throws Exception {
305
306
  dbName = getDatabaseName(dbName);
307
+ String connName = readonly ? "RO_" + dbName : "RW_" + dbName;
306
308
  // check if connection already exists
307
- Database conn = dbDict.get(dbName);
309
+ Database conn = dbDict.get(connName);
308
310
  if (conn != null) {
309
311
  String msg = "Connection " + dbName + " already exists";
310
312
  throw new Exception(msg);
@@ -321,10 +323,11 @@ public class CapacitorSQLite {
321
323
  version,
322
324
  isEncryption,
323
325
  vUpgObject,
324
- sharedPreferences
326
+ sharedPreferences,
327
+ readonly
325
328
  );
326
329
  if (db != null) {
327
- dbDict.put(dbName, db);
330
+ dbDict.put(connName, db);
328
331
  return;
329
332
  } else {
330
333
  String msg = "db is null";
@@ -337,13 +340,15 @@ public class CapacitorSQLite {
337
340
 
338
341
  /**
339
342
  * CreateNCConnection
343
+ *
340
344
  * @param dbPath
341
345
  * @param version
342
346
  * @throws Exception
343
347
  */
344
348
  public void createNCConnection(String dbPath, int version) throws Exception {
345
349
  // check if connection already exists
346
- Database conn = dbDict.get(dbPath);
350
+ String connName = "RO_" + dbPath;
351
+ Database conn = dbDict.get(connName);
347
352
  if (conn != null) {
348
353
  String msg = "Connection " + dbPath + " already exists";
349
354
  throw new Exception(msg);
@@ -362,7 +367,8 @@ public class CapacitorSQLite {
362
367
  version,
363
368
  isEncryption,
364
369
  new Hashtable<>(),
365
- sharedPreferences
370
+ sharedPreferences,
371
+ true
366
372
  );
367
373
  if (db != null) {
368
374
  dbDict.put(dbPath, db);
@@ -378,12 +384,14 @@ public class CapacitorSQLite {
378
384
 
379
385
  /**
380
386
  * Open
387
+ *
381
388
  * @param dbName
382
389
  * @throws Exception
383
390
  */
384
- public void open(String dbName) throws Exception {
391
+ public void open(String dbName, Boolean readonly) throws Exception {
385
392
  dbName = getDatabaseName(dbName);
386
- Database db = dbDict.get(dbName);
393
+ String connName = readonly ? "RO_" + dbName : "RW_" + dbName;
394
+ Database db = dbDict.get(connName);
387
395
  if (db != null) {
388
396
  try {
389
397
  db.open();
@@ -399,12 +407,14 @@ public class CapacitorSQLite {
399
407
 
400
408
  /**
401
409
  * Close
410
+ *
402
411
  * @param dbName
403
412
  * @throws Exception
404
413
  */
405
- public void close(String dbName) throws Exception {
414
+ public void close(String dbName, Boolean readonly) throws Exception {
406
415
  dbName = getDatabaseName(dbName);
407
- Database db = dbDict.get(dbName);
416
+ String connName = readonly ? "RO_" + dbName : "RW_" + dbName;
417
+ Database db = dbDict.get(connName);
408
418
  if (db != null) {
409
419
  if (db.isOpen()) {
410
420
  if (!db.inTransaction()) {
@@ -430,13 +440,15 @@ public class CapacitorSQLite {
430
440
 
431
441
  /**
432
442
  * GetUrl
443
+ *
433
444
  * @param dbName
434
- * @throws Exception
435
445
  * @return String
446
+ * @throws Exception
436
447
  */
437
- public String getUrl(String dbName) throws Exception {
448
+ public String getUrl(String dbName, Boolean readonly) throws Exception {
438
449
  dbName = getDatabaseName(dbName);
439
- Database db = dbDict.get(dbName);
450
+ String connName = readonly ? "RO_" + dbName : "RW_" + dbName;
451
+ Database db = dbDict.get(connName);
440
452
  if (db != null) {
441
453
  try {
442
454
  String url = db.getUrl();
@@ -452,13 +464,15 @@ public class CapacitorSQLite {
452
464
 
453
465
  /**
454
466
  * GetVersion
467
+ *
455
468
  * @param dbName
456
- * @throws Exception
457
469
  * @return Integer
470
+ * @throws Exception
458
471
  */
459
- public Integer getVersion(String dbName) throws Exception {
472
+ public Integer getVersion(String dbName, Boolean readonly) throws Exception {
460
473
  dbName = getDatabaseName(dbName);
461
- Database db = dbDict.get(dbName);
474
+ String connName = readonly ? "RO_" + dbName : "RW_" + dbName;
475
+ Database db = dbDict.get(connName);
462
476
  if (db != null) {
463
477
  try {
464
478
  Integer version = db.getVersion();
@@ -474,20 +488,22 @@ public class CapacitorSQLite {
474
488
 
475
489
  /**
476
490
  * CloseNCConnection
491
+ *
477
492
  * @param dbPath
478
493
  * @throws Exception
479
494
  */
480
495
  public void closeNCConnection(String dbPath) throws Exception {
496
+ String connName = "RO_" + dbPath;
481
497
  Database db = dbDict.get(dbPath);
482
498
  if (db != null) {
483
499
  if (db.isOpen()) {
484
500
  try {
485
- close(dbPath);
501
+ db.close();
486
502
  } catch (Exception e) {
487
503
  throw new Exception(e.getMessage());
488
504
  }
489
505
  }
490
- dbDict.remove(dbPath);
506
+ dbDict.remove(connName);
491
507
  return;
492
508
  } else {
493
509
  String msg = "No available connection for database " + dbPath;
@@ -497,21 +513,23 @@ public class CapacitorSQLite {
497
513
 
498
514
  /**
499
515
  * CloseConnection
516
+ *
500
517
  * @param dbName
501
518
  * @throws Exception
502
519
  */
503
- public void closeConnection(String dbName) throws Exception {
520
+ public void closeConnection(String dbName, Boolean readonly) throws Exception {
504
521
  dbName = getDatabaseName(dbName);
505
- Database db = dbDict.get(dbName);
522
+ String connName = readonly ? "RO_" + dbName : "RW_" + dbName;
523
+ Database db = dbDict.get(connName);
506
524
  if (db != null) {
507
525
  if (db.isOpen()) {
508
526
  try {
509
- close(dbName);
527
+ db.close();
510
528
  } catch (Exception e) {
511
529
  throw new Exception(e.getMessage());
512
530
  }
513
531
  }
514
- dbDict.remove(dbName);
532
+ dbDict.remove(connName);
515
533
  return;
516
534
  } else {
517
535
  String msg = "No available connection for database " + dbName;
@@ -565,6 +583,7 @@ public class CapacitorSQLite {
565
583
 
566
584
  /**
567
585
  * IsDatabase
586
+ *
568
587
  * @param dbName
569
588
  * @return Boolean
570
589
  * @throws Exception
@@ -576,6 +595,7 @@ public class CapacitorSQLite {
576
595
 
577
596
  /**
578
597
  * IsNCDatabase
598
+ *
579
599
  * @param dbPath
580
600
  * @return Boolean
581
601
  * @throws Exception
@@ -586,13 +606,15 @@ public class CapacitorSQLite {
586
606
 
587
607
  /**
588
608
  * IsTableExists
609
+ *
589
610
  * @param dbName
590
611
  * @param tableName
591
612
  * @throws Exception
592
613
  */
593
- public Boolean isTableExists(String dbName, String tableName) throws Exception {
614
+ public Boolean isTableExists(String dbName, String tableName, Boolean readonly) throws Exception {
594
615
  dbName = getDatabaseName(dbName);
595
- Database db = dbDict.get(dbName);
616
+ String connName = readonly ? "RO_" + dbName : "RW_" + dbName;
617
+ Database db = dbDict.get(connName);
596
618
  if (db != null) {
597
619
  boolean res = uJson.isTableExists(db, tableName);
598
620
  return res;
@@ -604,6 +626,7 @@ public class CapacitorSQLite {
604
626
 
605
627
  /**
606
628
  * GetDatabaseList
629
+ *
607
630
  * @return JSArray
608
631
  * @throws Exception
609
632
  */
@@ -623,6 +646,7 @@ public class CapacitorSQLite {
623
646
 
624
647
  /**
625
648
  * GetMigratableDbList
649
+ *
626
650
  * @return JSArray
627
651
  * @throws Exception
628
652
  */
@@ -642,6 +666,7 @@ public class CapacitorSQLite {
642
666
 
643
667
  /**
644
668
  * AddSQLiteSuffix
669
+ *
645
670
  * @param folderPath
646
671
  * @throws Exception
647
672
  */
@@ -656,7 +681,6 @@ public class CapacitorSQLite {
656
681
  }
657
682
 
658
683
  /**
659
- *
660
684
  * @param folderPath
661
685
  * @throws Exception
662
686
  */
@@ -687,15 +711,20 @@ public class CapacitorSQLite {
687
711
 
688
712
  /**
689
713
  * Execute
714
+ *
690
715
  * @param dbName
691
716
  * @param statements
692
717
  * @return
693
718
  * @throws Exception
694
719
  */
695
- public JSObject execute(String dbName, String statements, Boolean transaction) throws Exception {
720
+ public JSObject execute(String dbName, String statements, Boolean transaction, Boolean readonly) throws Exception {
696
721
  dbName = getDatabaseName(dbName);
697
- Database db = dbDict.get(dbName);
722
+ String connName = "RW_" + dbName;
723
+ Database db = dbDict.get(connName);
698
724
  if (db != null) {
725
+ if (readonly) {
726
+ throw new Exception("not allowed in read-only mode");
727
+ }
699
728
  if (!db.isNCDB() && db.isOpen()) {
700
729
  // convert string in string[]
701
730
  String[] sqlCmdArray = uSqlite.getStatementsArray(statements);
@@ -717,15 +746,20 @@ public class CapacitorSQLite {
717
746
 
718
747
  /**
719
748
  * ExecuteSet
749
+ *
720
750
  * @param dbName
721
751
  * @param set
722
752
  * @return
723
753
  * @throws Exception
724
754
  */
725
- public JSObject executeSet(String dbName, JSArray set, Boolean transaction) throws Exception {
755
+ public JSObject executeSet(String dbName, JSArray set, Boolean transaction, Boolean readonly) throws Exception {
726
756
  dbName = getDatabaseName(dbName);
727
- Database db = dbDict.get(dbName);
757
+ String connName = "RW_" + dbName;
758
+ Database db = dbDict.get(connName);
728
759
  if (db != null) {
760
+ if (readonly) {
761
+ throw new Exception("not allowed in read-only mode");
762
+ }
729
763
  if (!db.isNCDB() && db.isOpen()) {
730
764
  try {
731
765
  JSObject res = db.executeSet(set, transaction);
@@ -745,17 +779,22 @@ public class CapacitorSQLite {
745
779
 
746
780
  /**
747
781
  * Run
782
+ *
748
783
  * @param dbName
749
784
  * @param statement
750
785
  * @param values
751
786
  * @return
752
787
  * @throws Exception
753
788
  */
754
- public JSObject run(String dbName, String statement, JSArray values, Boolean transaction) throws Exception {
789
+ public JSObject run(String dbName, String statement, JSArray values, Boolean transaction, Boolean readonly) throws Exception {
755
790
  JSObject res;
756
791
  dbName = getDatabaseName(dbName);
757
- Database db = dbDict.get(dbName);
792
+ String connName = "RW_" + dbName;
793
+ Database db = dbDict.get(connName);
758
794
  if (db != null) {
795
+ if (readonly) {
796
+ throw new Exception("not allowed in read-only mode");
797
+ }
759
798
  if (!db.isNCDB() && db.isOpen()) {
760
799
  if (values.length() > 0) {
761
800
  try {
@@ -787,16 +826,18 @@ public class CapacitorSQLite {
787
826
 
788
827
  /**
789
828
  * Query
829
+ *
790
830
  * @param dbName
791
831
  * @param statement
792
832
  * @param values
793
833
  * @return
794
834
  * @throws Exception
795
835
  */
796
- public JSArray query(String dbName, String statement, JSArray values) throws Exception {
836
+ public JSArray query(String dbName, String statement, JSArray values, Boolean readonly) throws Exception {
797
837
  JSArray res;
798
838
  dbName = getDatabaseName(dbName);
799
- Database db = dbDict.get(dbName);
839
+ String connName = readonly ? "RO_" + dbName : "RW_" + dbName;
840
+ Database db = dbDict.get(connName);
800
841
  if (db != null) {
801
842
  if (db.isOpen()) {
802
843
  if (values.length() > 0) {
@@ -827,10 +868,10 @@ public class CapacitorSQLite {
827
868
  }
828
869
  }
829
870
 
830
- public JSArray getTableList(String dbName) throws Exception {
871
+ public JSArray getTableList(String dbName, Boolean readonly) throws Exception {
831
872
  JSArray res;
832
- dbName = getDatabaseName(dbName);
833
- Database db = dbDict.get(dbName);
873
+ String connName = readonly ? "RO_" + dbName : "RW_" + dbName;
874
+ Database db = dbDict.get(connName);
834
875
  if (db != null) {
835
876
  if (db.isOpen()) {
836
877
  res = db.getTableNames();
@@ -845,42 +886,40 @@ public class CapacitorSQLite {
845
886
  }
846
887
  }
847
888
 
848
- public Boolean isDBExists(String dbName) throws Exception {
889
+ public Boolean isDBExists(String dbName, Boolean readonly) throws Exception {
849
890
  dbName = getDatabaseName(dbName);
850
- Database db = dbDict.get(dbName);
891
+ String connName = readonly ? "RO_" + dbName : "RW_" + dbName;
892
+ Database db = dbDict.get(connName);
851
893
  if (db != null) {
852
894
  File databaseFile = context.getDatabasePath(dbName + "SQLite.db");
853
- if (databaseFile.exists()) {
854
- return true;
855
- } else {
856
- return false;
857
- }
895
+ return databaseFile.exists();
858
896
  } else {
859
897
  String msg = "No available connection for database " + dbName;
860
898
  throw new Exception(msg);
861
899
  }
862
900
  }
863
901
 
864
- public Boolean isDBOpen(String dbName) throws Exception {
902
+ public Boolean isDBOpen(String dbName, Boolean readonly) throws Exception {
865
903
  dbName = getDatabaseName(dbName);
866
- Database db = dbDict.get(dbName);
904
+ String connName = readonly ? "RO_" + dbName : "RW_" + dbName;
905
+ Database db = dbDict.get(connName);
867
906
  if (db != null) {
868
907
  Boolean isOpen = db.isOpen();
869
- if (isOpen) {
870
- return true;
871
- } else {
872
- return false;
873
- }
908
+ return isOpen;
874
909
  } else {
875
910
  String msg = "No available connection for database " + dbName;
876
911
  throw new Exception(msg);
877
912
  }
878
913
  }
879
914
 
880
- public void deleteDatabase(String dbName) throws Exception {
915
+ public void deleteDatabase(String dbName, Boolean readonly) throws Exception {
881
916
  dbName = getDatabaseName(dbName);
882
- Database db = dbDict.get(dbName);
917
+ String connName = "RW_" + dbName;
918
+ Database db = dbDict.get(connName);
883
919
  if (db != null) {
920
+ if (readonly) {
921
+ throw new Exception("not allowed in read-only mode");
922
+ }
884
923
  try {
885
924
  db.deleteDB(dbName + "SQLite.db");
886
925
  return;
@@ -893,10 +932,14 @@ public class CapacitorSQLite {
893
932
  }
894
933
  }
895
934
 
896
- public JSObject createSyncTable(String dbName) throws Exception {
935
+ public JSObject createSyncTable(String dbName, Boolean readonly) throws Exception {
897
936
  dbName = getDatabaseName(dbName);
898
- Database db = dbDict.get(dbName);
937
+ String connName = "RW_" + dbName;
938
+ Database db = dbDict.get(connName);
899
939
  if (db != null) {
940
+ if (readonly) {
941
+ throw new Exception("not allowed in read-only mode");
942
+ }
900
943
  try {
901
944
  if (!db.isOpen()) {
902
945
  String msg = "CreateSyncTable: db not opened";
@@ -913,10 +956,14 @@ public class CapacitorSQLite {
913
956
  }
914
957
  }
915
958
 
916
- public void setSyncDate(String dbName, String syncDate) throws Exception {
959
+ public void setSyncDate(String dbName, String syncDate, Boolean readonly) throws Exception {
917
960
  dbName = getDatabaseName(dbName);
918
- Database db = dbDict.get(dbName);
961
+ String connName = "RW_" + dbName;
962
+ Database db = dbDict.get(connName);
919
963
  if (db != null) {
964
+ if (readonly) {
965
+ throw new Exception("not allowed in read-only mode");
966
+ }
920
967
  try {
921
968
  if (!db.isOpen()) {
922
969
  String msg = "SetSyncDate: db not opened";
@@ -933,9 +980,10 @@ public class CapacitorSQLite {
933
980
  }
934
981
  }
935
982
 
936
- public Long getSyncDate(String dbName) throws Exception {
983
+ public Long getSyncDate(String dbName, Boolean readonly) throws Exception {
937
984
  dbName = getDatabaseName(dbName);
938
- Database db = dbDict.get(dbName);
985
+ String connName = readonly ? "RO_" + dbName : "RW_" + dbName;
986
+ Database db = dbDict.get(connName);
939
987
  if (db != null) {
940
988
  try {
941
989
  if (!db.isOpen()) {
@@ -964,17 +1012,17 @@ public class CapacitorSQLite {
964
1012
  throw new Exception(msg);
965
1013
  }
966
1014
 
967
- if (upgObj == null || !upgObj.has("fromVersion") || !upgObj.has("toVersion") || !upgObj.has("statement")) {
1015
+ if (upgObj == null || !upgObj.has("toVersion") || !upgObj.has("statements")) {
968
1016
  String msg = "Must provide an upgrade statement";
969
- msg += " {fromVersion,toVersion,statement}";
1017
+ msg += " {toVersion,statement}";
970
1018
  throw new Exception(msg);
971
1019
  }
972
1020
  try {
973
- int fromVersion = upgObj.getInt("fromVersion");
974
- upgDict.put(fromVersion, upgObj);
1021
+ int toVersion = upgObj.getInt("toVersion");
1022
+ upgDict.put(toVersion, upgObj);
975
1023
  return upgDict;
976
1024
  } catch (Exception e) {
977
- String msg = "Must provide fromVersion as Integer" + e.getMessage();
1025
+ String msg = "Must provide toVersion as Integer" + e.getMessage();
978
1026
  throw new Exception(msg);
979
1027
  }
980
1028
  }
@@ -1010,7 +1058,17 @@ public class CapacitorSQLite {
1010
1058
  if (encrypted) {
1011
1059
  inMode = "secret";
1012
1060
  }
1013
- Database db = new Database(context, dbName, encrypted, inMode, dbVersion, isEncryption, new Hashtable<>(), sharedPreferences);
1061
+ Database db = new Database(
1062
+ context,
1063
+ dbName,
1064
+ encrypted,
1065
+ inMode,
1066
+ dbVersion,
1067
+ isEncryption,
1068
+ new Hashtable<>(),
1069
+ sharedPreferences,
1070
+ false
1071
+ );
1014
1072
  if (overwrite && mode.equals("full")) {
1015
1073
  Boolean isExists = this.uFile.isFileExists(context, dbName);
1016
1074
  if (isExists) {
@@ -1052,9 +1110,10 @@ public class CapacitorSQLite {
1052
1110
  }
1053
1111
  }
1054
1112
 
1055
- public JSObject exportToJson(String dbName, String expMode) throws Exception {
1113
+ public JSObject exportToJson(String dbName, String expMode, Boolean readonly) throws Exception {
1056
1114
  dbName = getDatabaseName(dbName);
1057
- Database db = dbDict.get(dbName);
1115
+ String connName = readonly ? "RO_" + dbName : "RW_" + dbName;
1116
+ Database db = dbDict.get(connName);
1058
1117
  if (db != null) {
1059
1118
  try {
1060
1119
  if (!db.isOpen()) {
@@ -1081,10 +1140,14 @@ public class CapacitorSQLite {
1081
1140
  }
1082
1141
  }
1083
1142
 
1084
- public void deleteExportedRows(String dbName) throws Exception {
1143
+ public void deleteExportedRows(String dbName, Boolean readonly) throws Exception {
1085
1144
  dbName = getDatabaseName(dbName);
1086
- Database db = dbDict.get(dbName);
1145
+ String connName = "RW_" + dbName;
1146
+ Database db = dbDict.get(connName);
1087
1147
  if (db != null) {
1148
+ if (readonly) {
1149
+ throw new Exception("not allowed in read-only mode");
1150
+ }
1088
1151
  try {
1089
1152
  if (!db.isOpen()) {
1090
1153
  String msg = "deleteExportedRows: db not opened";
@@ -1128,8 +1191,13 @@ public class CapacitorSQLite {
1128
1191
  try {
1129
1192
  Enumeration<String> connections = dbDict.keys();
1130
1193
  while (connections.hasMoreElements()) {
1131
- String dbName = (String) connections.nextElement();
1132
- closeConnection(dbName);
1194
+ String dbName = connections.nextElement();
1195
+ Boolean readonly = false;
1196
+ if (dbName.substring(0, 3).equals("RO_")) {
1197
+ readonly = true;
1198
+ }
1199
+ dbName = dbName.substring(3);
1200
+ closeConnection(dbName, readonly);
1133
1201
  }
1134
1202
  } catch (Exception e) {
1135
1203
  String msg = "close all connections " + e.getMessage();