@capacitor-community/sqlite 4.1.0-5 → 4.1.0-6
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 -2
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +77 -70
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +73 -88
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +45 -319
- package/dist/esm/definitions.d.ts +3 -6
- package/dist/esm/definitions.js +2 -4
- package/dist/esm/definitions.js.map +1 -1
- package/dist/plugin.cjs.js +2 -4
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +2 -4
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +41 -304
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +5 -7
- package/ios/Plugin/Database.swift +8 -7
- package/ios/Plugin/Utils/UtilsUpgrade.swift +46 -370
- package/package.json +2 -2
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
|
|
|
@@ -111,7 +111,7 @@ npm install --save-dev @types/sqlite3
|
|
|
111
111
|
| getSyncDate | ✅ | ✅ | ✅ | ✅ |
|
|
112
112
|
| isJsonValid | ✅ | ✅ | ✅ | ✅ |
|
|
113
113
|
| isDBExists | ✅ | ✅ | ✅ | ✅ |
|
|
114
|
-
| addUpgradeStatement | ✅ | ✅ | ✅ | ✅ |
|
|
114
|
+
| addUpgradeStatement | ✅ | ✅ | ✅ | ✅ | Modified 4.1.0-6
|
|
115
115
|
| copyFromAssets | ✅ | ✅ | ✅ | ✅ |
|
|
116
116
|
| isDBOpen | ✅ | ✅ | ✅ | ✅ |
|
|
117
117
|
| isDatabase | ✅ | ✅ | ✅ | ✅ |
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java
CHANGED
|
@@ -2,14 +2,14 @@ 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;
|
|
7
|
+
|
|
8
8
|
import androidx.biometric.BiometricManager;
|
|
9
9
|
import androidx.biometric.BiometricPrompt;
|
|
10
10
|
import androidx.security.crypto.EncryptedSharedPreferences;
|
|
11
11
|
import androidx.security.crypto.MasterKey;
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
import com.getcapacitor.JSArray;
|
|
14
14
|
import com.getcapacitor.JSObject;
|
|
15
15
|
import com.getcapacitor.PluginCall;
|
|
@@ -24,14 +24,13 @@ import com.getcapacitor.community.database.sqlite.SQLite.UtilsMigrate;
|
|
|
24
24
|
import com.getcapacitor.community.database.sqlite.SQLite.UtilsNCDatabase;
|
|
25
25
|
import com.getcapacitor.community.database.sqlite.SQLite.UtilsSQLite;
|
|
26
26
|
import com.getcapacitor.community.database.sqlite.SQLite.UtilsSecret;
|
|
27
|
+
|
|
28
|
+
import org.json.JSONException;
|
|
29
|
+
import org.json.JSONObject;
|
|
30
|
+
|
|
27
31
|
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
32
|
import java.security.KeyStore;
|
|
33
33
|
import java.util.ArrayList;
|
|
34
|
-
import java.util.Arrays;
|
|
35
34
|
import java.util.Collections;
|
|
36
35
|
import java.util.Dictionary;
|
|
37
36
|
import java.util.Enumeration;
|
|
@@ -40,32 +39,28 @@ import java.util.HashSet;
|
|
|
40
39
|
import java.util.Hashtable;
|
|
41
40
|
import java.util.Map;
|
|
42
41
|
import java.util.Set;
|
|
43
|
-
import javax.crypto.BadPaddingException;
|
|
44
|
-
import javax.crypto.IllegalBlockSizeException;
|
|
45
|
-
import org.json.JSONException;
|
|
46
|
-
import org.json.JSONObject;
|
|
47
42
|
|
|
48
43
|
public class CapacitorSQLite {
|
|
49
44
|
|
|
50
45
|
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();
|
|
46
|
+
private final Context context;
|
|
47
|
+
private final Dictionary<String, Database> dbDict = new Hashtable<>();
|
|
48
|
+
private final UtilsSQLite uSqlite = new UtilsSQLite();
|
|
49
|
+
private final UtilsFile uFile = new UtilsFile();
|
|
50
|
+
private final UtilsJson uJson = new UtilsJson();
|
|
51
|
+
private final UtilsMigrate uMigrate = new UtilsMigrate();
|
|
52
|
+
private final UtilsNCDatabase uNCDatabase = new UtilsNCDatabase();
|
|
58
53
|
private UtilsSecret uSecret;
|
|
59
54
|
private SharedPreferences sharedPreferences = null;
|
|
60
55
|
private MasterKey masterKeyAlias;
|
|
61
56
|
private BiometricManager biometricManager;
|
|
62
|
-
private SqliteConfig config;
|
|
57
|
+
private final SqliteConfig config;
|
|
63
58
|
private Boolean isEncryption = true;
|
|
64
59
|
private Boolean biometricAuth = false;
|
|
65
|
-
private String biometricTitle;
|
|
66
|
-
private String biometricSubTitle;
|
|
67
|
-
private int VALIDITY_DURATION = 5;
|
|
68
|
-
private RetHandler rHandler = new RetHandler();
|
|
60
|
+
private final String biometricTitle;
|
|
61
|
+
private final String biometricSubTitle;
|
|
62
|
+
private final int VALIDITY_DURATION = 5;
|
|
63
|
+
private final RetHandler rHandler = new RetHandler();
|
|
69
64
|
private PluginCall call;
|
|
70
65
|
|
|
71
66
|
public CapacitorSQLite(Context context, SqliteConfig config) throws Exception {
|
|
@@ -92,10 +87,10 @@ public class CapacitorSQLite {
|
|
|
92
87
|
Enumeration<String> aliases = ks.aliases();
|
|
93
88
|
if (aliases.hasMoreElements()) {
|
|
94
89
|
masterKeyAlias =
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
new MasterKey.Builder(context)
|
|
91
|
+
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
|
|
92
|
+
.setUserAuthenticationRequired(true, VALIDITY_DURATION)
|
|
93
|
+
.build();
|
|
99
94
|
} else {
|
|
100
95
|
masterKeyAlias = new MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build();
|
|
101
96
|
}
|
|
@@ -150,13 +145,13 @@ public class CapacitorSQLite {
|
|
|
150
145
|
try {
|
|
151
146
|
// get instance of the EncryptedSharedPreferences class
|
|
152
147
|
this.sharedPreferences =
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
148
|
+
EncryptedSharedPreferences.create(
|
|
149
|
+
context,
|
|
150
|
+
"sqlite_encrypted_shared_prefs",
|
|
151
|
+
masterKeyAlias,
|
|
152
|
+
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
|
|
153
|
+
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
|
|
154
|
+
);
|
|
160
155
|
this.uSecret = new UtilsSecret(this.context, this.sharedPreferences);
|
|
161
156
|
} catch (Exception e) {
|
|
162
157
|
throw new Exception(e.getMessage());
|
|
@@ -165,6 +160,7 @@ public class CapacitorSQLite {
|
|
|
165
160
|
|
|
166
161
|
/**
|
|
167
162
|
* Echo
|
|
163
|
+
*
|
|
168
164
|
* @param value
|
|
169
165
|
* @return
|
|
170
166
|
*/
|
|
@@ -189,6 +185,7 @@ public class CapacitorSQLite {
|
|
|
189
185
|
|
|
190
186
|
/**
|
|
191
187
|
* SetEncryptionSecret
|
|
188
|
+
*
|
|
192
189
|
* @param passphrase
|
|
193
190
|
* @throws Exception
|
|
194
191
|
*/
|
|
@@ -209,6 +206,7 @@ public class CapacitorSQLite {
|
|
|
209
206
|
|
|
210
207
|
/**
|
|
211
208
|
* ChangeEncryptionSecret
|
|
209
|
+
*
|
|
212
210
|
* @param passphrase
|
|
213
211
|
* @param oldPassphrase
|
|
214
212
|
* @throws Exception
|
|
@@ -293,6 +291,7 @@ public class CapacitorSQLite {
|
|
|
293
291
|
|
|
294
292
|
/**
|
|
295
293
|
* CreateConnection
|
|
294
|
+
*
|
|
296
295
|
* @param dbName
|
|
297
296
|
* @param encrypted
|
|
298
297
|
* @param mode
|
|
@@ -301,7 +300,7 @@ public class CapacitorSQLite {
|
|
|
301
300
|
* @throws Exception
|
|
302
301
|
*/
|
|
303
302
|
public void createConnection(String dbName, boolean encrypted, String mode, int version, Dictionary<Integer, JSONObject> vUpgObject)
|
|
304
|
-
|
|
303
|
+
throws Exception {
|
|
305
304
|
dbName = getDatabaseName(dbName);
|
|
306
305
|
// check if connection already exists
|
|
307
306
|
Database conn = dbDict.get(dbName);
|
|
@@ -314,14 +313,14 @@ public class CapacitorSQLite {
|
|
|
314
313
|
}
|
|
315
314
|
try {
|
|
316
315
|
Database db = new Database(
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
316
|
+
context,
|
|
317
|
+
dbName + "SQLite.db",
|
|
318
|
+
encrypted,
|
|
319
|
+
mode,
|
|
320
|
+
version,
|
|
321
|
+
isEncryption,
|
|
322
|
+
vUpgObject,
|
|
323
|
+
sharedPreferences
|
|
325
324
|
);
|
|
326
325
|
if (db != null) {
|
|
327
326
|
dbDict.put(dbName, db);
|
|
@@ -337,6 +336,7 @@ public class CapacitorSQLite {
|
|
|
337
336
|
|
|
338
337
|
/**
|
|
339
338
|
* CreateNCConnection
|
|
339
|
+
*
|
|
340
340
|
* @param dbPath
|
|
341
341
|
* @param version
|
|
342
342
|
* @throws Exception
|
|
@@ -355,14 +355,14 @@ public class CapacitorSQLite {
|
|
|
355
355
|
throw new Exception(msg);
|
|
356
356
|
}
|
|
357
357
|
Database db = new Database(
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
358
|
+
context,
|
|
359
|
+
dbPath,
|
|
360
|
+
false,
|
|
361
|
+
"no-encryption",
|
|
362
|
+
version,
|
|
363
|
+
isEncryption,
|
|
364
|
+
new Hashtable<>(),
|
|
365
|
+
sharedPreferences
|
|
366
366
|
);
|
|
367
367
|
if (db != null) {
|
|
368
368
|
dbDict.put(dbPath, db);
|
|
@@ -378,6 +378,7 @@ public class CapacitorSQLite {
|
|
|
378
378
|
|
|
379
379
|
/**
|
|
380
380
|
* Open
|
|
381
|
+
*
|
|
381
382
|
* @param dbName
|
|
382
383
|
* @throws Exception
|
|
383
384
|
*/
|
|
@@ -399,6 +400,7 @@ public class CapacitorSQLite {
|
|
|
399
400
|
|
|
400
401
|
/**
|
|
401
402
|
* Close
|
|
403
|
+
*
|
|
402
404
|
* @param dbName
|
|
403
405
|
* @throws Exception
|
|
404
406
|
*/
|
|
@@ -430,9 +432,10 @@ public class CapacitorSQLite {
|
|
|
430
432
|
|
|
431
433
|
/**
|
|
432
434
|
* GetUrl
|
|
435
|
+
*
|
|
433
436
|
* @param dbName
|
|
434
|
-
* @throws Exception
|
|
435
437
|
* @return String
|
|
438
|
+
* @throws Exception
|
|
436
439
|
*/
|
|
437
440
|
public String getUrl(String dbName) throws Exception {
|
|
438
441
|
dbName = getDatabaseName(dbName);
|
|
@@ -452,9 +455,10 @@ public class CapacitorSQLite {
|
|
|
452
455
|
|
|
453
456
|
/**
|
|
454
457
|
* GetVersion
|
|
458
|
+
*
|
|
455
459
|
* @param dbName
|
|
456
|
-
* @throws Exception
|
|
457
460
|
* @return Integer
|
|
461
|
+
* @throws Exception
|
|
458
462
|
*/
|
|
459
463
|
public Integer getVersion(String dbName) throws Exception {
|
|
460
464
|
dbName = getDatabaseName(dbName);
|
|
@@ -474,6 +478,7 @@ public class CapacitorSQLite {
|
|
|
474
478
|
|
|
475
479
|
/**
|
|
476
480
|
* CloseNCConnection
|
|
481
|
+
*
|
|
477
482
|
* @param dbPath
|
|
478
483
|
* @throws Exception
|
|
479
484
|
*/
|
|
@@ -497,6 +502,7 @@ public class CapacitorSQLite {
|
|
|
497
502
|
|
|
498
503
|
/**
|
|
499
504
|
* CloseConnection
|
|
505
|
+
*
|
|
500
506
|
* @param dbName
|
|
501
507
|
* @throws Exception
|
|
502
508
|
*/
|
|
@@ -565,6 +571,7 @@ public class CapacitorSQLite {
|
|
|
565
571
|
|
|
566
572
|
/**
|
|
567
573
|
* IsDatabase
|
|
574
|
+
*
|
|
568
575
|
* @param dbName
|
|
569
576
|
* @return Boolean
|
|
570
577
|
* @throws Exception
|
|
@@ -576,6 +583,7 @@ public class CapacitorSQLite {
|
|
|
576
583
|
|
|
577
584
|
/**
|
|
578
585
|
* IsNCDatabase
|
|
586
|
+
*
|
|
579
587
|
* @param dbPath
|
|
580
588
|
* @return Boolean
|
|
581
589
|
* @throws Exception
|
|
@@ -586,6 +594,7 @@ public class CapacitorSQLite {
|
|
|
586
594
|
|
|
587
595
|
/**
|
|
588
596
|
* IsTableExists
|
|
597
|
+
*
|
|
589
598
|
* @param dbName
|
|
590
599
|
* @param tableName
|
|
591
600
|
* @throws Exception
|
|
@@ -604,6 +613,7 @@ public class CapacitorSQLite {
|
|
|
604
613
|
|
|
605
614
|
/**
|
|
606
615
|
* GetDatabaseList
|
|
616
|
+
*
|
|
607
617
|
* @return JSArray
|
|
608
618
|
* @throws Exception
|
|
609
619
|
*/
|
|
@@ -623,6 +633,7 @@ public class CapacitorSQLite {
|
|
|
623
633
|
|
|
624
634
|
/**
|
|
625
635
|
* GetMigratableDbList
|
|
636
|
+
*
|
|
626
637
|
* @return JSArray
|
|
627
638
|
* @throws Exception
|
|
628
639
|
*/
|
|
@@ -642,6 +653,7 @@ public class CapacitorSQLite {
|
|
|
642
653
|
|
|
643
654
|
/**
|
|
644
655
|
* AddSQLiteSuffix
|
|
656
|
+
*
|
|
645
657
|
* @param folderPath
|
|
646
658
|
* @throws Exception
|
|
647
659
|
*/
|
|
@@ -656,7 +668,6 @@ public class CapacitorSQLite {
|
|
|
656
668
|
}
|
|
657
669
|
|
|
658
670
|
/**
|
|
659
|
-
*
|
|
660
671
|
* @param folderPath
|
|
661
672
|
* @throws Exception
|
|
662
673
|
*/
|
|
@@ -687,6 +698,7 @@ public class CapacitorSQLite {
|
|
|
687
698
|
|
|
688
699
|
/**
|
|
689
700
|
* Execute
|
|
701
|
+
*
|
|
690
702
|
* @param dbName
|
|
691
703
|
* @param statements
|
|
692
704
|
* @return
|
|
@@ -717,6 +729,7 @@ public class CapacitorSQLite {
|
|
|
717
729
|
|
|
718
730
|
/**
|
|
719
731
|
* ExecuteSet
|
|
732
|
+
*
|
|
720
733
|
* @param dbName
|
|
721
734
|
* @param set
|
|
722
735
|
* @return
|
|
@@ -745,6 +758,7 @@ public class CapacitorSQLite {
|
|
|
745
758
|
|
|
746
759
|
/**
|
|
747
760
|
* Run
|
|
761
|
+
*
|
|
748
762
|
* @param dbName
|
|
749
763
|
* @param statement
|
|
750
764
|
* @param values
|
|
@@ -787,6 +801,7 @@ public class CapacitorSQLite {
|
|
|
787
801
|
|
|
788
802
|
/**
|
|
789
803
|
* Query
|
|
804
|
+
*
|
|
790
805
|
* @param dbName
|
|
791
806
|
* @param statement
|
|
792
807
|
* @param values
|
|
@@ -850,11 +865,7 @@ public class CapacitorSQLite {
|
|
|
850
865
|
Database db = dbDict.get(dbName);
|
|
851
866
|
if (db != null) {
|
|
852
867
|
File databaseFile = context.getDatabasePath(dbName + "SQLite.db");
|
|
853
|
-
|
|
854
|
-
return true;
|
|
855
|
-
} else {
|
|
856
|
-
return false;
|
|
857
|
-
}
|
|
868
|
+
return databaseFile.exists();
|
|
858
869
|
} else {
|
|
859
870
|
String msg = "No available connection for database " + dbName;
|
|
860
871
|
throw new Exception(msg);
|
|
@@ -866,11 +877,7 @@ public class CapacitorSQLite {
|
|
|
866
877
|
Database db = dbDict.get(dbName);
|
|
867
878
|
if (db != null) {
|
|
868
879
|
Boolean isOpen = db.isOpen();
|
|
869
|
-
|
|
870
|
-
return true;
|
|
871
|
-
} else {
|
|
872
|
-
return false;
|
|
873
|
-
}
|
|
880
|
+
return isOpen;
|
|
874
881
|
} else {
|
|
875
882
|
String msg = "No available connection for database " + dbName;
|
|
876
883
|
throw new Exception(msg);
|
|
@@ -964,17 +971,17 @@ public class CapacitorSQLite {
|
|
|
964
971
|
throw new Exception(msg);
|
|
965
972
|
}
|
|
966
973
|
|
|
967
|
-
if (upgObj == null || !upgObj.has("
|
|
974
|
+
if (upgObj == null || !upgObj.has("toVersion") || !upgObj.has("statements")) {
|
|
968
975
|
String msg = "Must provide an upgrade statement";
|
|
969
|
-
msg += " {
|
|
976
|
+
msg += " {toVersion,statement}";
|
|
970
977
|
throw new Exception(msg);
|
|
971
978
|
}
|
|
972
979
|
try {
|
|
973
|
-
int
|
|
974
|
-
upgDict.put(
|
|
980
|
+
int toVersion = upgObj.getInt("toVersion");
|
|
981
|
+
upgDict.put(toVersion, upgObj);
|
|
975
982
|
return upgDict;
|
|
976
983
|
} catch (Exception e) {
|
|
977
|
-
String msg = "Must provide
|
|
984
|
+
String msg = "Must provide toVersion as Integer" + e.getMessage();
|
|
978
985
|
throw new Exception(msg);
|
|
979
986
|
}
|
|
980
987
|
}
|
|
@@ -1128,7 +1135,7 @@ public class CapacitorSQLite {
|
|
|
1128
1135
|
try {
|
|
1129
1136
|
Enumeration<String> connections = dbDict.keys();
|
|
1130
1137
|
while (connections.hasMoreElements()) {
|
|
1131
|
-
String dbName =
|
|
1138
|
+
String dbName = connections.nextElement();
|
|
1132
1139
|
closeConnection(dbName);
|
|
1133
1140
|
}
|
|
1134
1141
|
} catch (Exception e) {
|