@capacitor-community/sqlite 3.2.5-1 → 3.3.2
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/CHANGELOG.md +45 -0
- package/CapacitorCommunitySqlite.podspec +1 -0
- package/README.md +26 -117
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +5 -5
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +3 -2
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +0 -7
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsFile.java +71 -11
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsMigrate.java +34 -15
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +0 -1
- package/dist/esm/definitions.d.ts +13 -4
- package/dist/esm/definitions.js +3 -2
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +2 -2
- package/dist/esm/web.js +2 -2
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +5 -4
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +5 -4
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +69 -25
- package/electron/dist/plugin.js.map +1 -1
- package/electron/rollup.config.js +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +19 -5
- package/ios/Plugin/CapacitorSQLitePlugin.swift +3 -1
- package/ios/Plugin/ImportExportJson/ExportToJson.swift +0 -1
- package/ios/Plugin/Utils/UtilsFile.swift +98 -34
- package/ios/Plugin/Utils/UtilsMigrate.swift +59 -13
- package/ios/Plugin/Utils/UtilsSecret.swift +2 -8
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
+
## 3.3.2 (2021-12-13)
|
|
2
|
+
|
|
3
|
+
### Chore
|
|
4
|
+
|
|
5
|
+
- Update to @capacitor/core 3.3.2
|
|
6
|
+
- Update to @capacitor/ios 3.3.2
|
|
7
|
+
- Update to @capacitor/android 3.3.2
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
- fix addSQLiteSuffix skips databases without .db extension issue#200
|
|
12
|
+
|
|
13
|
+
## 3.3.1 (2021-11-25)
|
|
14
|
+
|
|
15
|
+
### Chore
|
|
16
|
+
|
|
17
|
+
- Update to @capacitor/core 3.3.1
|
|
18
|
+
- Update to @capacitor/ios 3.3.1
|
|
19
|
+
- Update to @capacitor/android 3.3.1
|
|
20
|
+
|
|
21
|
+
### Added Features
|
|
22
|
+
|
|
23
|
+
- add link to React-Vite and Vue-Vite application
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
- fix Plugin failed to register in Android 11 physical device issue#196
|
|
28
|
+
- fix Ionic-React-Usage.md
|
|
29
|
+
- fix Ionic-Vue-Usage.md
|
|
30
|
+
- fix Electron `npm install --save jszip`in README issue#197
|
|
31
|
+
|
|
32
|
+
## 3.2.5 (2021-11-07)
|
|
33
|
+
|
|
34
|
+
- stable release
|
|
35
|
+
|
|
36
|
+
## 3.2.5-2 (2021-11-03)
|
|
37
|
+
|
|
38
|
+
### Added Features
|
|
39
|
+
|
|
40
|
+
- add importing zipped files using copyFromAssets method
|
|
41
|
+
|
|
42
|
+
### Bug Fixes
|
|
43
|
+
|
|
44
|
+
- fix issue#191
|
|
45
|
+
|
|
1
46
|
## 3.2.5-1 (2021-10-22)
|
|
2
47
|
|
|
3
48
|
### Chore
|
package/README.md
CHANGED
|
@@ -28,6 +28,13 @@
|
|
|
28
28
|
|
|
29
29
|
## CAPACITOR 3 (Master)
|
|
30
30
|
|
|
31
|
+
🚨 Since release 3.2.5-2 ->> 🚨
|
|
32
|
+
|
|
33
|
+
- support zip file in copyFromAssets method
|
|
34
|
+
- add optional `overwrite` parameter (true/false) default to true
|
|
35
|
+
|
|
36
|
+
🚨 Since release 3.2.5-2 <<- 🚨
|
|
37
|
+
|
|
31
38
|
🚨 Since release 3.2.3-1 ->> 🚨
|
|
32
39
|
|
|
33
40
|
The `initWebStore` and `saveToStore` methods have been added to the Web platform.
|
|
@@ -46,72 +53,7 @@ The `initWebStore` and `saveToStore` methods have been added to the Web platform
|
|
|
46
53
|
```
|
|
47
54
|
- the `saveToStore` allows to perform intermediate save of the database in case the browser needs to delete the cache.
|
|
48
55
|
|
|
49
|
-
🚨 Since release 3.2.
|
|
50
|
-
|
|
51
|
-
The executeSet method accepts now no values, see below
|
|
52
|
-
|
|
53
|
-
```
|
|
54
|
-
const setIssue170: Array<capSQLiteSet> = [
|
|
55
|
-
{ statement: "DROP TABLE IF EXISTS issue170", values: [] },
|
|
56
|
-
{ statement: "CREATE TABLE issue170 (src VARCHAR(255))", values: [] },
|
|
57
|
-
{ statement: "INSERT INTO issue170 (src) values (?)", values: ["google.com"] },
|
|
58
|
-
]
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
🚨 Since release 3.2.0-5 ->> 🚨
|
|
62
|
-
|
|
63
|
-
The Web plugin is now implemented based on the stencil companion `jeep-sqlite@0.0.7` which is using `sql.js@1.5.0` for database queries and `localeforage@1.9.0`for database persistency.
|
|
64
|
-
|
|
65
|
-
🚨 Since release 3.2.0-3 ->> 🚨
|
|
66
|
-
|
|
67
|
-
The Electron plugin is now based on `@capacitor-community/electron@4.0.3` thanks to the hard and heavy work from `Mike Summerfeldt IT-MikeS` 👏 🙏
|
|
68
|
-
|
|
69
|
-
🚨 Since release 3.2.0-2 ->> 🚨
|
|
70
|
-
🚨 !!! for Electron developper, the Electron plugin is back !!! 🚨
|
|
71
|
-
|
|
72
|
-
Based on `sqlite3`, so without encryption
|
|
73
|
-
The two listeners `sqliteImportProgressEvent` and `sqliteExportProgressEvent` are not available.
|
|
74
|
-
|
|
75
|
-
🚨 Since release 3.1.2 ->> 🚨
|
|
76
|
-
|
|
77
|
-
Thanks to Nirajhinge and Chris, an example of using the TypeORM driver in a Ionic/Vue app has been developed see `https://github.com/jepiqueau/vue-typeorm-app`.
|
|
78
|
-
|
|
79
|
-
🚨 Since release 3.0.0-rc.2 ->> 🚨
|
|
80
|
-
|
|
81
|
-
Thanks to Chris, a driver to TypeORM is now available
|
|
82
|
-
|
|
83
|
-
🚨 Since release 3.0.0-beta.13 ->> 🚨
|
|
84
|
-
|
|
85
|
-
- GlobalSQLite `secret` and `newsecret` are deprecated
|
|
86
|
-
|
|
87
|
-
- The user can now set its own secure secret (passphrase)
|
|
88
|
-
|
|
89
|
-
- use `setEncryptionSecret` ONCE to migrate encrypted databases
|
|
90
|
-
from `secret` to `secure stored secret`
|
|
91
|
-
|
|
92
|
-
- use `changeEncryptionSecret` to change your `secure stored secret`
|
|
93
|
-
|
|
94
|
-
- iOS used `KeyChain service` to store the `secret`
|
|
95
|
-
|
|
96
|
-
- Android used `Encrypted SharedPreferences` to store the `secret`,
|
|
97
|
-
the minimun sdk should be set to 23 (limitation from Google)
|
|
98
|
-
|
|
99
|
-
🚨 Since release 3.0.0-beta.13 ->> 🚨
|
|
100
|
-
|
|
101
|
-
🚨 Since release 3.0.0-beta.11 ->> 🚨
|
|
102
|
-
|
|
103
|
-
- Checking of types has been removed in all methods of the plugin
|
|
104
|
-
both iOS & Android. This has been achieved to allow the use of
|
|
105
|
-
others RDBMS types.
|
|
106
|
-
The type checking is now under the responsability of the developers.
|
|
107
|
-
|
|
108
|
-
- NULL values are now returned as null
|
|
109
|
-
|
|
110
|
-
- values for the `query` method is now an Array of any.
|
|
111
|
-
|
|
112
|
-
- option to disable `transaction` for the `execute`, `executeSet`, `run`.
|
|
113
|
-
|
|
114
|
-
🚨 Since release 3.0.0-beta.11 <<- 🚨
|
|
56
|
+
🚨 Since release 3.2.3-1 <<- 🚨
|
|
115
57
|
|
|
116
58
|
The test has been achieved on:
|
|
117
59
|
|
|
@@ -121,55 +63,6 @@ The test has been achieved on:
|
|
|
121
63
|
|
|
122
64
|
- a [Ionic/Vue app](https://github.com/jepiqueau/vue-sqlite-app-starter)
|
|
123
65
|
|
|
124
|
-
## REFACTOR (Move to branch 2.9.x)
|
|
125
|
-
|
|
126
|
-
The `2.9.x` is now 🛑 NOT MAINTAINED ANYMORE 🛑.
|
|
127
|
-
|
|
128
|
-
The refactor offers now (since `2.9.0-beta.1`) all the features that the previous was offering. It has been a quite heavy process, hoping that the developpers will take benefit from it.
|
|
129
|
-
|
|
130
|
-
The main reasons for it:
|
|
131
|
-
|
|
132
|
-
- multiple database connections
|
|
133
|
-
- db connector allowing for easy commands `db.open(), db.close, ...`
|
|
134
|
-
- improve the response time of the encrypted database by removing the internal open and close database for each sqlite query
|
|
135
|
-
- moving to the latest `androidx.sqlite.db.xxx`
|
|
136
|
-
- offering encryption for Electron platform by using `@journeyapps/sqlcipher` on MacOs, !!! NOT ON WINDOWS !!!
|
|
137
|
-
- cleaning and aligning the code between platforms
|
|
138
|
-
- allowing developers to develop `typeorm` or `spatialite` drivers.
|
|
139
|
-
|
|
140
|
-
This was discussed lengthly in issue#1 and issue#52
|
|
141
|
-
|
|
142
|
-
Refactor available for `Android`, `iOS` and `Electron` platforms.
|
|
143
|
-
|
|
144
|
-
The test has been achieved on:
|
|
145
|
-
|
|
146
|
-
- a [Ionic/Angular app](https://github.com/jepiqueau/angular-sqlite-app-starter/tree/refactor)
|
|
147
|
-
|
|
148
|
-
- a [Ionic/React app](https://github.com/jepiqueau/react-sqlite-app-starter/tree/refactor)
|
|
149
|
-
|
|
150
|
-
- a [Ionic/Vue app](https://github.com/jepiqueau/vue-sqlite-app-starter/tree/refactor)
|
|
151
|
-
|
|
152
|
-
Other frameworks will be tested later
|
|
153
|
-
|
|
154
|
-
- Stencil
|
|
155
|
-
|
|
156
|
-
## @INITIAL 🛑 (Move to branch 2.4.x)
|
|
157
|
-
|
|
158
|
-
The `2.4.x` is now 🛑 NOT MAINTAINED ANYMORE 🛑.
|
|
159
|
-
|
|
160
|
-
To install it
|
|
161
|
-
|
|
162
|
-
```bash
|
|
163
|
-
npm i --save @capacitor-community/sqlite@initial
|
|
164
|
-
```
|
|
165
|
-
The test has been achieved on:
|
|
166
|
-
|
|
167
|
-
- a [Ionic/Angular app](https://github.com/jepiqueau/angular-sqlite-app-starter/tree/2.4.x)
|
|
168
|
-
|
|
169
|
-
- a [Ionic/React app](https://github.com/jepiqueau/react-sqlite-app-starter/tree/2.4.x)
|
|
170
|
-
|
|
171
|
-
- a [Ionic/Vue app](https://github.com/jepiqueau/vue-sqlite-app-starter/tree/2.4.x)
|
|
172
|
-
|
|
173
66
|
|
|
174
67
|
## Browser Support
|
|
175
68
|
|
|
@@ -222,6 +115,7 @@ npx cap sync @capacitor-community/electron
|
|
|
222
115
|
```bash
|
|
223
116
|
cd electron
|
|
224
117
|
npm install --save sqlite3
|
|
118
|
+
npm install --save jszip
|
|
225
119
|
npm install --save-dev @types/sqlite3
|
|
226
120
|
npm run build
|
|
227
121
|
```
|
|
@@ -266,6 +160,11 @@ npx cap open android
|
|
|
266
160
|
```
|
|
267
161
|
npx cap open @capacitor-community/electron
|
|
268
162
|
```
|
|
163
|
+
|
|
164
|
+
## Readme previous releases
|
|
165
|
+
|
|
166
|
+
[previous releases](https://github.com/capacitor-community/sqlite/readme_previous_release.md)
|
|
167
|
+
|
|
269
168
|
## Issues
|
|
270
169
|
|
|
271
170
|
[issues](https://github.com/capacitor-community/sqlite/issues)
|
|
@@ -357,6 +256,11 @@ No configuration required for this plugin
|
|
|
357
256
|
|
|
358
257
|
- [react-sqlite-app-starter](https://github.com/jepiqueau/react-sqlite-app-starter)
|
|
359
258
|
|
|
259
|
+
### React+Vite
|
|
260
|
+
|
|
261
|
+
- [react-vite-sqlite-app](https://github.com/jepiqueau/react-vite-sqlite-app)
|
|
262
|
+
|
|
263
|
+
|
|
360
264
|
### Ionic/Vue
|
|
361
265
|
|
|
362
266
|
- [vue-sqlite-app-starter](https://github.com/jepiqueau/vue-sqlite-app-starter)
|
|
@@ -365,6 +269,10 @@ No configuration required for this plugin
|
|
|
365
269
|
|
|
366
270
|
- [vue-sqlite-app](https://github.com/jepiqueau/vue-sqlite-app)
|
|
367
271
|
|
|
272
|
+
### Vue+Vite
|
|
273
|
+
|
|
274
|
+
- [vue-vite-sqlite-app](https://github.com/jepiqueau/vuevite-app)
|
|
275
|
+
|
|
368
276
|
## Usage
|
|
369
277
|
|
|
370
278
|
- [see capacitor documentation](https://capacitor.ionicframework.com/docs/getting-started/with-ionic)
|
|
@@ -372,9 +280,10 @@ No configuration required for this plugin
|
|
|
372
280
|
|
|
373
281
|
## Dependencies
|
|
374
282
|
|
|
375
|
-
The
|
|
283
|
+
The iOS and Android codes are using `SQLCipher` allowing for database encryption.
|
|
284
|
+
The iOS codes is using `ZIPFoundation` for unzipping assets files
|
|
376
285
|
The Electron code is using `sqlite3`.
|
|
377
|
-
The Web code is using the Stencil component `jeep-sqlite` based on `sql.js` and `
|
|
286
|
+
The Web code is using the Stencil component `jeep-sqlite` based on `sql.js`, `localforage`. and `jszip`
|
|
378
287
|
|
|
379
288
|
## Contributors ✨
|
|
380
289
|
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java
CHANGED
|
@@ -5,6 +5,7 @@ import android.content.SharedPreferences;
|
|
|
5
5
|
import android.text.TextUtils;
|
|
6
6
|
import android.util.Log;
|
|
7
7
|
import androidx.security.crypto.EncryptedSharedPreferences;
|
|
8
|
+
import androidx.security.crypto.MasterKey;
|
|
8
9
|
import androidx.security.crypto.MasterKeys;
|
|
9
10
|
import com.getcapacitor.JSArray;
|
|
10
11
|
import com.getcapacitor.JSObject;
|
|
@@ -46,14 +47,13 @@ public class CapacitorSQLite {
|
|
|
46
47
|
try {
|
|
47
48
|
// create or retrieve masterkey from Android keystore
|
|
48
49
|
// it will be used to encrypt the passphrase for a database
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
MasterKey masterKeyAlias = new MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build();
|
|
51
51
|
// get instance of the EncryptedSharedPreferences class
|
|
52
52
|
this.sharedPreferences =
|
|
53
53
|
EncryptedSharedPreferences.create(
|
|
54
|
+
context,
|
|
54
55
|
"sqlite_encrypted_shared_prefs",
|
|
55
56
|
masterKeyAlias,
|
|
56
|
-
context,
|
|
57
57
|
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
|
|
58
58
|
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
|
|
59
59
|
);
|
|
@@ -724,10 +724,10 @@ public class CapacitorSQLite {
|
|
|
724
724
|
}
|
|
725
725
|
}
|
|
726
726
|
|
|
727
|
-
public void copyFromAssets() throws Exception {
|
|
727
|
+
public void copyFromAssets(Boolean overwrite) throws Exception {
|
|
728
728
|
String msg = "copy failed : ";
|
|
729
729
|
try {
|
|
730
|
-
uFile.copyFromAssetsToDatabase(context);
|
|
730
|
+
uFile.copyFromAssetsToDatabase(context, overwrite);
|
|
731
731
|
return;
|
|
732
732
|
} catch (Exception e) {
|
|
733
733
|
msg += e.getMessage();
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java
CHANGED
|
@@ -562,7 +562,6 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
562
562
|
return;
|
|
563
563
|
}
|
|
564
564
|
JSArray values = call.getArray("values");
|
|
565
|
-
Log.v(TAG, "CapacitorSQLitePlugin: " + values);
|
|
566
565
|
|
|
567
566
|
Boolean transaction = call.getBoolean("transaction", true);
|
|
568
567
|
|
|
@@ -897,8 +896,10 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
897
896
|
*/
|
|
898
897
|
@PluginMethod
|
|
899
898
|
public void copyFromAssets(PluginCall call) {
|
|
899
|
+
Boolean overwrite = call.getData().has("overwrite") ? call.getBoolean("overwrite") : true;
|
|
900
|
+
|
|
900
901
|
try {
|
|
901
|
-
implementation.copyFromAssets();
|
|
902
|
+
implementation.copyFromAssets(overwrite);
|
|
902
903
|
rHandler.retResult(call, null, null);
|
|
903
904
|
return;
|
|
904
905
|
} catch (Exception e) {
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java
CHANGED
|
@@ -95,7 +95,6 @@ public class Database {
|
|
|
95
95
|
* Initialize the SQLCipher Libraries
|
|
96
96
|
*/
|
|
97
97
|
private void InitializeSQLCipher() {
|
|
98
|
-
Log.d(TAG, " in InitializeSQLCipher: ");
|
|
99
98
|
SQLiteDatabase.loadLibs(_context);
|
|
100
99
|
}
|
|
101
100
|
|
|
@@ -286,7 +285,6 @@ public class Database {
|
|
|
286
285
|
if (transaction) _db.beginTransaction();
|
|
287
286
|
for (String cmd : statements) {
|
|
288
287
|
if (!cmd.endsWith(";")) cmd += ";";
|
|
289
|
-
Log.v(TAG, " cmd " + cmd);
|
|
290
288
|
_db.execSQL(cmd);
|
|
291
289
|
}
|
|
292
290
|
changes = _uSqlite.dbChanges(_db) - initChanges;
|
|
@@ -319,7 +317,6 @@ public class Database {
|
|
|
319
317
|
try {
|
|
320
318
|
if (_db != null && _db.isOpen()) {
|
|
321
319
|
Integer initChanges = _uSqlite.dbChanges(_db);
|
|
322
|
-
Log.v(TAG, "ExecuteSet InitChanges " + initChanges);
|
|
323
320
|
if (transaction) _db.beginTransaction();
|
|
324
321
|
for (int i = 0; i < set.length(); i++) {
|
|
325
322
|
JSONObject row = set.getJSONObject(i);
|
|
@@ -348,7 +345,6 @@ public class Database {
|
|
|
348
345
|
if (lastId != -1) {
|
|
349
346
|
if (transaction) _db.setTransactionSuccessful();
|
|
350
347
|
changes = _uSqlite.dbChanges(_db) - initChanges;
|
|
351
|
-
Log.v(TAG, "Execute Changes " + changes);
|
|
352
348
|
retObj.put("changes", changes);
|
|
353
349
|
retObj.put("lastId", lastId);
|
|
354
350
|
return retObj;
|
|
@@ -388,12 +384,10 @@ public class Database {
|
|
|
388
384
|
try {
|
|
389
385
|
if (_db != null && _db.isOpen() && statement.length() > 0) {
|
|
390
386
|
Integer initChanges = _uSqlite.dbChanges(_db);
|
|
391
|
-
Log.v(TAG, "runSQL InitChanges " + initChanges);
|
|
392
387
|
if (transaction) _db.beginTransaction();
|
|
393
388
|
lastId = prepareSQL(statement, values);
|
|
394
389
|
if (lastId != -1 && transaction) _db.setTransactionSuccessful();
|
|
395
390
|
changes = _uSqlite.dbChanges(_db) - initChanges;
|
|
396
|
-
Log.v(TAG, "runSQL Changes " + changes);
|
|
397
391
|
retObj.put("changes", changes);
|
|
398
392
|
retObj.put("lastId", lastId);
|
|
399
393
|
return retObj;
|
|
@@ -601,7 +595,6 @@ public class Database {
|
|
|
601
595
|
* @return
|
|
602
596
|
*/
|
|
603
597
|
public JSObject importFromJson(JsonSQLite jsonSQL) throws Exception {
|
|
604
|
-
Log.d(TAG, "importFromJson: ");
|
|
605
598
|
JSObject retObj = new JSObject();
|
|
606
599
|
int changes = Integer.valueOf(0);
|
|
607
600
|
try {
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsFile.java
CHANGED
|
@@ -12,6 +12,8 @@ import java.io.OutputStream;
|
|
|
12
12
|
import java.nio.channels.FileChannel;
|
|
13
13
|
import java.util.ArrayList;
|
|
14
14
|
import java.util.List;
|
|
15
|
+
import java.util.zip.ZipEntry;
|
|
16
|
+
import java.util.zip.ZipInputStream;
|
|
15
17
|
|
|
16
18
|
public class UtilsFile {
|
|
17
19
|
|
|
@@ -53,7 +55,7 @@ public class UtilsFile {
|
|
|
53
55
|
return file.delete();
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
public void copyFromAssetsToDatabase(Context context) throws Exception {
|
|
58
|
+
public void copyFromAssetsToDatabase(Context context, Boolean overwrite) throws Exception {
|
|
57
59
|
AssetManager assetManager = context.getAssets();
|
|
58
60
|
String assetsDatabasePath = "public/assets/databases";
|
|
59
61
|
try {
|
|
@@ -73,22 +75,80 @@ public class UtilsFile {
|
|
|
73
75
|
for (int i = 0; i < filelist.length; i++) {
|
|
74
76
|
// Get filename of file or directory
|
|
75
77
|
String fileName = filelist[i];
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
if (isLast(fileName, ".db")) {
|
|
79
|
+
String toFileName = addSQLiteSuffix(fileName);
|
|
80
|
+
boolean isExist = isFileExists(context, toFileName);
|
|
81
|
+
if (!isExist || overwrite) {
|
|
82
|
+
if (overwrite && isExist) {
|
|
83
|
+
deleteDatabase(context, toFileName);
|
|
84
|
+
}
|
|
85
|
+
String fromPathName = assetsDatabasePath + "/" + fileName;
|
|
86
|
+
String toPathName = context.getDatabasePath(toFileName).getAbsolutePath();
|
|
87
|
+
copyDatabaseFromAssets(assetManager, fromPathName, toPathName);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (isLast(fileName, ".zip")) {
|
|
91
|
+
// unzip file and extract databases
|
|
92
|
+
String zipPathName = assetsDatabasePath + "/" + fileName;
|
|
93
|
+
unzipCopyDatabase(context, assetManager, zipPathName, assetsDatabasePath, overwrite);
|
|
82
94
|
}
|
|
83
|
-
String fromPathName = assetsDatabasePath + "/" + fileName;
|
|
84
|
-
String toPathName = context.getDatabasePath(toFileName).getAbsolutePath();
|
|
85
|
-
copyDatabaseFromAssets(assetManager, fromPathName, toPathName);
|
|
86
95
|
}
|
|
87
96
|
return;
|
|
88
97
|
}
|
|
89
98
|
} catch (IOException e) {
|
|
90
|
-
throw new Exception("in
|
|
99
|
+
throw new Exception("in copyFromAssetsToDatabase " + e.getLocalizedMessage());
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public void unzipCopyDatabase(Context context, AssetManager asm, String zipPath, String assetsDatabasePath, Boolean overwrite)
|
|
104
|
+
throws IOException {
|
|
105
|
+
InputStream is;
|
|
106
|
+
byte[] buffer = new byte[1024];
|
|
107
|
+
try {
|
|
108
|
+
is = asm.open(zipPath);
|
|
109
|
+
ZipInputStream zis = new ZipInputStream(is);
|
|
110
|
+
|
|
111
|
+
ZipEntry ze = zis.getNextEntry();
|
|
112
|
+
while (ze != null) {
|
|
113
|
+
String fileName = ze.getName();
|
|
114
|
+
if (isLast(fileName, ".db")) {
|
|
115
|
+
String toFileName = addSQLiteSuffix(fileName);
|
|
116
|
+
boolean isExist = isFileExists(context, toFileName);
|
|
117
|
+
if (!isExist || overwrite) {
|
|
118
|
+
if (overwrite && isExist) {
|
|
119
|
+
deleteDatabase(context, toFileName);
|
|
120
|
+
}
|
|
121
|
+
String toPathName = context.getDatabasePath(toFileName).getAbsolutePath();
|
|
122
|
+
File newFile = new File(toPathName);
|
|
123
|
+
System.out.println("Unzipping to " + newFile.getAbsolutePath());
|
|
124
|
+
FileOutputStream fos = new FileOutputStream(newFile);
|
|
125
|
+
int len;
|
|
126
|
+
while ((len = zis.read(buffer)) > 0) {
|
|
127
|
+
fos.write(buffer, 0, len);
|
|
128
|
+
}
|
|
129
|
+
fos.close();
|
|
130
|
+
}
|
|
131
|
+
//close this ZipEntry
|
|
132
|
+
zis.closeEntry();
|
|
133
|
+
ze = zis.getNextEntry();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//close last ZipEntry
|
|
137
|
+
zis.closeEntry();
|
|
138
|
+
zis.close();
|
|
139
|
+
is.close();
|
|
140
|
+
} catch (IOException e) {
|
|
141
|
+
throw new IOException("in unzipCopyDatabase " + e.getLocalizedMessage());
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public String addSQLiteSuffix(String fileName) {
|
|
146
|
+
String toFileName = fileName;
|
|
147
|
+
boolean isSQLite = isLast(fileName, "SQLite.db");
|
|
148
|
+
if (!isSQLite) {
|
|
149
|
+
toFileName = fileName.substring(0, fileName.length() - 3) + "SQLite.db";
|
|
91
150
|
}
|
|
151
|
+
return toFileName;
|
|
92
152
|
}
|
|
93
153
|
|
|
94
154
|
public void copyDatabaseFromAssets(AssetManager asm, String inPath, String outPath) throws IOException {
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsMigrate.java
CHANGED
|
@@ -43,17 +43,28 @@ public class UtilsMigrate {
|
|
|
43
43
|
throw new Exception("Folder " + dir + " no database files");
|
|
44
44
|
}
|
|
45
45
|
for (String file : listFiles) {
|
|
46
|
-
if (
|
|
47
|
-
|
|
46
|
+
if (!file.contains("SQLite.db")) {
|
|
47
|
+
String fromFile = file;
|
|
48
|
+
String toFile = "";
|
|
49
|
+
if (dbList.size() > 0) {
|
|
48
50
|
if (dbList.contains(file)) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
String msg = "Failed in copy " + fromFile + " to " + file;
|
|
54
|
-
throw new Exception(msg);
|
|
51
|
+
if (uFile.getFileExtension((file)).equals("db")) {
|
|
52
|
+
toFile = file.replace(".db", "SQLite.db");
|
|
53
|
+
} else {
|
|
54
|
+
toFile = file.concat("SQLite.db");
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
+
} else {
|
|
58
|
+
if (uFile.getFileExtension((file)).equals("db")) {
|
|
59
|
+
toFile = file.replace(".db", "SQLite.db");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (toFile.length() > 0) {
|
|
63
|
+
boolean ret = uFile.copyFromNames(context, pathFiles, fromFile, pathDB, toFile);
|
|
64
|
+
if (!ret) {
|
|
65
|
+
String msg = "Failed in copy " + fromFile + " to " + file;
|
|
66
|
+
throw new Exception(msg);
|
|
67
|
+
}
|
|
57
68
|
}
|
|
58
69
|
}
|
|
59
70
|
}
|
|
@@ -89,14 +100,22 @@ public class UtilsMigrate {
|
|
|
89
100
|
}
|
|
90
101
|
String[] listFiles = dir.list();
|
|
91
102
|
for (String file : listFiles) {
|
|
92
|
-
|
|
93
|
-
|
|
103
|
+
String delFile = "";
|
|
104
|
+
if (!file.contains("SQLite.db")) {
|
|
105
|
+
if (dbList.size() > 0) {
|
|
94
106
|
if (dbList.contains(file)) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
107
|
+
delFile = file;
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
if (uFile.getFileExtension((file)).equals("db")) {
|
|
111
|
+
delFile = file;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (delFile.length() > 0) {
|
|
115
|
+
boolean ret = uFile.deleteFile(pathFiles, delFile);
|
|
116
|
+
if (!ret) {
|
|
117
|
+
String msg = "Failed in delete " + delFile;
|
|
118
|
+
throw new Exception(msg);
|
|
100
119
|
}
|
|
101
120
|
}
|
|
102
121
|
}
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java
CHANGED
|
@@ -333,7 +333,6 @@ public class UtilsUpgrade {
|
|
|
333
333
|
String stmt = "UPDATE sync_table SET ";
|
|
334
334
|
stmt += "sync_date = " + syncTime;
|
|
335
335
|
stmt += " WHERE id = 1;";
|
|
336
|
-
Log.v(TAG, "*** New SyncDate " + syncTime);
|
|
337
336
|
try {
|
|
338
337
|
db.runSQL(stmt, new ArrayList<>());
|
|
339
338
|
} catch (Exception e) {
|
|
@@ -201,11 +201,11 @@ export interface CapacitorSQLitePlugin {
|
|
|
201
201
|
addUpgradeStatement(options: capSQLiteUpgradeOptions): Promise<void>;
|
|
202
202
|
/**
|
|
203
203
|
* Copy databases from public/assets/databases folder to application databases folder
|
|
204
|
-
*
|
|
204
|
+
* @param options: capSQLiteFromAssets since 3.2.5-2
|
|
205
205
|
* @returns Promise<void>
|
|
206
206
|
* @since 2.9.0 refactor
|
|
207
207
|
*/
|
|
208
|
-
copyFromAssets(): Promise<void>;
|
|
208
|
+
copyFromAssets(options: capSQLiteFromAssetsOptions): Promise<void>;
|
|
209
209
|
/**
|
|
210
210
|
* Get the database list
|
|
211
211
|
* @returns Promise<capSQLiteValues>
|
|
@@ -384,6 +384,14 @@ export interface capSQLiteExportOptions {
|
|
|
384
384
|
*/
|
|
385
385
|
jsonexportmode?: string;
|
|
386
386
|
}
|
|
387
|
+
export interface capSQLiteFromAssetsOptions {
|
|
388
|
+
/**
|
|
389
|
+
* Set the overwrite mode for the copy from assets
|
|
390
|
+
* "true"/"false" default to "true"
|
|
391
|
+
*
|
|
392
|
+
*/
|
|
393
|
+
overwrite?: boolean;
|
|
394
|
+
}
|
|
387
395
|
export interface capSQLiteSyncDateOptions {
|
|
388
396
|
/**
|
|
389
397
|
* The database name
|
|
@@ -740,10 +748,11 @@ export interface ISQLiteConnection {
|
|
|
740
748
|
isJsonValid(jsonstring: string): Promise<capSQLiteResult>;
|
|
741
749
|
/**
|
|
742
750
|
* Copy databases from public/assets/databases folder to application databases folder
|
|
751
|
+
* @param overwrite since 3.2.5-2
|
|
743
752
|
* @returns Promise<void>
|
|
744
753
|
* @since 2.9.0 refactor
|
|
745
754
|
*/
|
|
746
|
-
copyFromAssets(): Promise<void>;
|
|
755
|
+
copyFromAssets(overwrite?: boolean): Promise<void>;
|
|
747
756
|
/**
|
|
748
757
|
* Check if a database exists
|
|
749
758
|
* @param database
|
|
@@ -804,7 +813,7 @@ export declare class SQLiteConnection implements ISQLiteConnection {
|
|
|
804
813
|
checkConnectionsConsistency(): Promise<capSQLiteResult>;
|
|
805
814
|
importFromJson(jsonstring: string): Promise<capSQLiteChanges>;
|
|
806
815
|
isJsonValid(jsonstring: string): Promise<capSQLiteResult>;
|
|
807
|
-
copyFromAssets(): Promise<void>;
|
|
816
|
+
copyFromAssets(overwrite?: boolean): Promise<void>;
|
|
808
817
|
isDatabase(database: string): Promise<capSQLiteResult>;
|
|
809
818
|
getDatabaseList(): Promise<capSQLiteValues>;
|
|
810
819
|
getMigratableDbList(folderPath: string): Promise<capSQLiteValues>;
|
package/dist/esm/definitions.js
CHANGED
|
@@ -186,9 +186,10 @@ export class SQLiteConnection {
|
|
|
186
186
|
return Promise.reject(err);
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
async copyFromAssets() {
|
|
189
|
+
async copyFromAssets(overwrite) {
|
|
190
|
+
const mOverwrite = overwrite != null ? overwrite : true;
|
|
190
191
|
try {
|
|
191
|
-
await this.sqlite.copyFromAssets();
|
|
192
|
+
await this.sqlite.copyFromAssets({ overwrite: mOverwrite });
|
|
192
193
|
return Promise.resolve();
|
|
193
194
|
}
|
|
194
195
|
catch (err) {
|