@capacitor-community/sqlite 6.0.1 → 6.0.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.
Files changed (32) hide show
  1. package/README.md +71 -91
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +12 -16
  4. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +2 -1
  5. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +73 -69
  6. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsDownloadFromHTTP.java +13 -12
  7. package/dist/esm/definitions.js +1 -3
  8. package/dist/esm/definitions.js.map +1 -1
  9. package/dist/esm/index.js +1 -1
  10. package/dist/esm/index.js.map +1 -1
  11. package/dist/esm/web.js.map +1 -1
  12. package/dist/plugin.cjs.js +2 -4
  13. package/dist/plugin.cjs.js.map +1 -1
  14. package/dist/plugin.js +2 -4
  15. package/dist/plugin.js.map +1 -1
  16. package/electron/dist/plugin.js +56 -144
  17. package/electron/dist/plugin.js.map +1 -1
  18. package/electron/rollup.config.js +1 -3
  19. package/ios/Plugin/CapacitorSQLite.swift +5 -5
  20. package/ios/Plugin/Database.swift +1 -1
  21. package/ios/Plugin/ImportExportJson/ExportToJson.swift +7 -7
  22. package/ios/Plugin/Models/KeychainServices.swift +1 -1
  23. package/ios/Plugin/Utils/UtilsBinding.swift +2 -2
  24. package/ios/Plugin/Utils/UtilsDelete.swift +4 -4
  25. package/ios/Plugin/Utils/UtilsDownloadFromHTTP.swift +2 -2
  26. package/ios/Plugin/Utils/UtilsDrop.swift +1 -1
  27. package/ios/Plugin/Utils/UtilsSQLCipher.swift +17 -17
  28. package/ios/Plugin/Utils/UtilsSQLStatement.swift +120 -121
  29. package/package.json +23 -21
  30. package/src/definitions.ts +44 -128
  31. package/src/index.ts +4 -8
  32. package/src/web.ts +60 -132
package/README.md CHANGED
@@ -2,30 +2,6 @@
2
2
  <h3 align="center">SQLITE DATABASE</h3>
3
3
  <p align="center"><strong><code>@capacitor-community/sqlite</code></strong></p>
4
4
  <br>
5
- <p align="center" style="font-size:50px;color:red"><strong>CAPACITOR 6</strong></p><br>
6
- <br>
7
- <!-- Note from the Owner - Start -->
8
- <p align="center" style="font-size:50px;color:red"><strong>Note from the Owner</strong></p>
9
- <!-- Note from the Owner - End -->
10
- <br>
11
- <!-- Message below Note from the Owner - Start -->
12
- <p align="left" style="font-size:47px">Start --></p>
13
- <br>
14
- <p align="left">
15
- I have been dedicated to developing and maintaining this plugin for many years since the inception of Ionic Capacitor. Now, at 73+ years old, and with my MacBook Pro becoming obsolete for running Capacitor 6 for iOS, I have made the decision to cease maintenance of the plugin. If anyone wishes to take ownership of this plugin, they are welcome to do so.
16
- </p>
17
- <br>
18
- <p align="left">
19
- It has been a great honor to be part of this development journey alongside the developer community. I am grateful to see many of you following me on this path and incorporating the plugin into your applications. Your comments and suggestions have motivated me to continuously improve it.
20
- </p>
21
- <br>
22
- <p align="left">
23
- I have made this decision due to several family-related troubles that require my full attention and time. Therefore, I will not be stepping back. Thank you to all of you for your support.
24
- </p>
25
- <br>
26
- <p align="left" style="font-size:47px">End <--</p>
27
- <!-- Message below Note from the Owner - End -->
28
- <br>
29
5
 
30
6
  <p align="center">
31
7
  Capacitor community plugin for Native and Electron SQLite Databases.
@@ -35,8 +11,8 @@ I have made this decision due to several family-related troubles that require my
35
11
  <br>
36
12
  <p align="center">
37
13
  <img src="https://img.shields.io/maintenance/yes/2024?style=flat-square" />
38
- <a href="https://github.com/capacitor-community/sqlite/actions?query=workflow%3A%22CI%22"><img src="https://img.shields.io/github/workflow/status/capacitor-community/sqlite/CI?style=flat-square" /></a>
39
- <a href="https://www.npmjs.com/package/@capacitor-community/sqlite"><img src="https://img.shields.io/npm/l/@capacitor-community/sqlite?style=flat-square" /></a>
14
+ <a href="https://github.com/capacitor-community/sqlite/actions?query=workflow%3A%22CI%22"><img src="https://img.shields.io/github/actions/workflow/status/capacitor-community/sqlite/ci.yml?style=flat-square" /></a>
15
+ <a href="https://www.npmjs.com/package/@capacitor-community/sqlite"><img src="https://img.shields.io/npm/l/@capacitor-community/sqlite?branch=master&style=flat-square" /></a>
40
16
  <br>
41
17
  <a href="https://www.npmjs.com/package/@capacitor-community/sqlite"><img src="https://img.shields.io/npm/dw/@capacitor-community/sqlite?style=flat-square" /></a>
42
18
  <a href="https://www.npmjs.com/package/@capacitor-community/sqlite"><img src="https://img.shields.io/npm/v/@capacitor-community/sqlite?style=flat-square" /></a>
@@ -48,9 +24,9 @@ I have made this decision due to several family-related troubles that require my
48
24
 
49
25
  ## Maintainers
50
26
 
51
- | Maintainer | GitHub | Social |
52
- | ----------------- | ----------------------------------------- | ------ |
53
- | Quéau Jean Pierre | [jepiqueau](https://github.com/jepiqueau) | |
27
+ | Maintainer | GitHub | Social |
28
+ | ---------- | ----------------------------------------- | --------------------------------------------- |
29
+ | Robin Genz | [robingenz](https://github.com/robingenz) | [@robin_genz](https://twitter.com/robin_genz) |
54
30
 
55
31
  To install:
56
32
 
@@ -66,7 +42,7 @@ npx cap sync
66
42
 
67
43
  ```
68
44
  pnpm install --save @capacitor-community/sqlite
69
- pnpm install --save @jeep-sqlite
45
+ pnpm install --save jeep-sqlite
70
46
  pnpm install --save sql.js
71
47
  npx cap sync
72
48
  ```
@@ -112,7 +88,7 @@ export default config;
112
88
  ## More Reading:
113
89
 
114
90
  - [Updating to Capacitor 5](https://capacitorjs.com/docs/updating/5-0)
115
- - [Releases](https://github.com/capacitor-community/sqlite/blob/master/info_releases.md)
91
+ - [Releases](https://github.com/capacitor-community/sqlite/blob/master/docs/info_releases.md)
116
92
  - [Changelog](https://github.com/capacitor-community/sqlite/blob/master/CHANGELOG.md)
117
93
  - [Issues](https://github.com/capacitor-community/sqlite/issues)
118
94
  - [Capacitor documentation](https://capacitorjs.com/docs/)
@@ -226,66 +202,66 @@ npm install --save-dev electron-builder@24.6.4
226
202
 
227
203
  ## Supported Methods by Platform
228
204
 
229
- | Name | Android | iOS | Electron | Web |
230
- | :-------------------------- | :------ | :-- | :------- | :-- |
231
- | createConnection (ReadWrite)| ✅ | ✅ | ✅ | ✅ |
232
- | createConnection (ReadOnly) | ✅ | ✅ | ✅ | ❌ | since 4.1.0-7
233
- | closeConnection (ReadWrite) | ✅ | ✅ | ✅ | ✅ |
234
- | closeConnection (ReadOnly) | ✅ | ✅ | ✅ | ❌ | since 4.1.0-7
235
- | isConnection (ReadWrite) | ✅ | ✅ | ✅ | ✅ |
236
- | isConnection (ReadOnly) | ✅ | ✅ | ✅ | ❌ | since 4.1.0-7
237
- | open (non-encrypted DB) | ✅ | ✅ | ✅ | ✅ |
238
- | open (encrypted DB) | ✅ | ✅ | ✅ | ❌ |
239
- | close | ✅ | ✅ | ✅ | ✅ |
240
- | getUrl | ✅ | ✅ | ❌ | ❌ |
241
- | getVersion | ✅ | ✅ | ✅ | ✅ |
242
- | execute | ✅ | ✅ | ✅ | ✅ |
243
- | executeSet | ✅ | ✅ | ✅ | ✅ |
244
- | run | ✅ | ✅ | ✅ | ✅ |
245
- | query | ✅ | ✅ | ✅ | ✅ |
246
- | deleteDatabase | ✅ | ✅ | ✅ | ✅ |
247
- | importFromJson | ✅ | ✅ | ✅ | ✅ |
248
- | exportToJson | ✅ | ✅ | ✅ | ✅ |
249
- | deleteExportedRows | ✅ | ✅ | ✅ | ✅ |
250
- | createSyncTable | ✅ | ✅ | ✅ | ✅ |
251
- | setSyncDate | ✅ | ✅ | ✅ | ✅ |
252
- | getSyncDate | ✅ | ✅ | ✅ | ✅ |
253
- | isJsonValid | ✅ | ✅ | ✅ | ✅ |
254
- | isDBExists | ✅ | ✅ | ✅ | ✅ |
255
- | addUpgradeStatement | ✅ | ✅ | ✅ | ✅ | Modified 4.1.0-6
256
- | copyFromAssets | ✅ | ✅ | ✅ | ✅ |
257
- | isDBOpen | ✅ | ✅ | ✅ | ✅ |
258
- | isDatabase | ✅ | ✅ | ✅ | ✅ |
259
- | isTableExists | ✅ | ✅ | ✅ | ✅ |
260
- | getTableList | ✅ | ✅ | ✅ | ✅ |
261
- | getDatabaseList | ✅ | ✅ | ✅ | ✅ |
262
- | getMigratableDbList | ✅ | ✅ | ❌ | ❌ |
263
- | addSQLiteSuffix | ✅ | ✅ | ❌ | ❌ |
264
- | deleteOldDatabases | ✅ | ✅ | ❌ | ❌ |
265
- | moveDatabasesAndAddSuffix | ✅ | ✅ | ❌ | ❌ |
266
- | checkConnectionsConsistency | ✅ | ✅ | ✅ | ✅ |
267
- | isSecretStored | ✅ | ✅ | ✅ | ❌ |
268
- | setEncryptionSecret | ✅ | ✅ | ✅ | ❌ |
269
- | changeEncryptionSecret | ✅ | ✅ | ✅ | ❌ |
270
- | clearEncryptionSecret | ✅ | ✅ | ✅ | ❌ |
271
- | checkEncryptionSecret | ✅ | ✅ | ✅ | ❌ |
272
- | initWebStore | ❌ | ❌ | ❌ | ✅ |
273
- | saveToStore | ❌ | ❌ | ❌ | ✅ |
274
- | getNCDatabasePath | ✅ | ✅ | ❌ | ❌ |
275
- | createNCConnection | ✅ | ✅ | ❌ | ❌ |
276
- | closeNCConnection | ✅ | ✅ | ❌ | ❌ |
277
- | isNCDatabase | ✅ | ✅ | ❌ | ❌ |
278
- | transaction | ✅ | ✅ | ✅ | ✅ |
279
- | getFromHTTPRequest | ✅ | ✅ | ✅ | ✅ | since 4.2.0
280
- | isDatabaseEncrypted | ✅ | ✅ | ✅ | ❌ | since 4.6.2-2
281
- | isInConfigEncryption | ✅ | ✅ | ✅ | ❌ | since 4.6.2-2
282
- | isInConfigBiometricAuth | ✅ | ✅ | ❌ | ❌ | since 4.6.2-2
283
- | getFromLocalDiskToStore | ❌ | ❌ | ❌ | ✅ | since 4.6.3
284
- | saveToLocalDisk | ❌ | ❌ | ❌ | ✅ | since 4.6.3
285
- | beginTransaction | ✅ | ✅ | ✅ | ✅ | since 5.0.7
286
- | commitTransaction | ✅ | ✅ | ✅ | ✅ | since 5.0.7
287
- | rollbackTransaction | ✅ | ✅ | ✅ | ✅ | since 5.0.7
288
- | isTransactionActive | ✅ | ✅ | ✅ | ✅ | since 5.0.7
205
+ | Name | Android | iOS | Electron | Web |
206
+ | :--------------------------- | :------ | :--- | :------- | :--- |
207
+ | createConnection (ReadWrite) | ✅ | ✅ | ✅ | ✅ |
208
+ | createConnection (ReadOnly) | ✅ | ✅ | ✅ | ❌ | since 4.1.0-7 |
209
+ | closeConnection (ReadWrite) | ✅ | ✅ | ✅ | ✅ |
210
+ | closeConnection (ReadOnly) | ✅ | ✅ | ✅ | ❌ | since 4.1.0-7 |
211
+ | isConnection (ReadWrite) | ✅ | ✅ | ✅ | ✅ |
212
+ | isConnection (ReadOnly) | ✅ | ✅ | ✅ | ❌ | since 4.1.0-7 |
213
+ | open (non-encrypted DB) | ✅ | ✅ | ✅ | ✅ |
214
+ | open (encrypted DB) | ✅ | ✅ | ✅ | ❌ |
215
+ | close | ✅ | ✅ | ✅ | ✅ |
216
+ | getUrl | ✅ | ✅ | ❌ | ❌ |
217
+ | getVersion | ✅ | ✅ | ✅ | ✅ |
218
+ | execute | ✅ | ✅ | ✅ | ✅ |
219
+ | executeSet | ✅ | ✅ | ✅ | ✅ |
220
+ | run | ✅ | ✅ | ✅ | ✅ |
221
+ | query | ✅ | ✅ | ✅ | ✅ |
222
+ | deleteDatabase | ✅ | ✅ | ✅ | ✅ |
223
+ | importFromJson | ✅ | ✅ | ✅ | ✅ |
224
+ | exportToJson | ✅ | ✅ | ✅ | ✅ |
225
+ | deleteExportedRows | ✅ | ✅ | ✅ | ✅ |
226
+ | createSyncTable | ✅ | ✅ | ✅ | ✅ |
227
+ | setSyncDate | ✅ | ✅ | ✅ | ✅ |
228
+ | getSyncDate | ✅ | ✅ | ✅ | ✅ |
229
+ | isJsonValid | ✅ | ✅ | ✅ | ✅ |
230
+ | isDBExists | ✅ | ✅ | ✅ | ✅ |
231
+ | addUpgradeStatement | ✅ | ✅ | ✅ | ✅ | Modified 4.1.0-6 |
232
+ | copyFromAssets | ✅ | ✅ | ✅ | ✅ |
233
+ | isDBOpen | ✅ | ✅ | ✅ | ✅ |
234
+ | isDatabase | ✅ | ✅ | ✅ | ✅ |
235
+ | isTableExists | ✅ | ✅ | ✅ | ✅ |
236
+ | getTableList | ✅ | ✅ | ✅ | ✅ |
237
+ | getDatabaseList | ✅ | ✅ | ✅ | ✅ |
238
+ | getMigratableDbList | ✅ | ✅ | ❌ | ❌ |
239
+ | addSQLiteSuffix | ✅ | ✅ | ❌ | ❌ |
240
+ | deleteOldDatabases | ✅ | ✅ | ❌ | ❌ |
241
+ | moveDatabasesAndAddSuffix | ✅ | ✅ | ❌ | ❌ |
242
+ | checkConnectionsConsistency | ✅ | ✅ | ✅ | ✅ |
243
+ | isSecretStored | ✅ | ✅ | ✅ | ❌ |
244
+ | setEncryptionSecret | ✅ | ✅ | ✅ | ❌ |
245
+ | changeEncryptionSecret | ✅ | ✅ | ✅ | ❌ |
246
+ | clearEncryptionSecret | ✅ | ✅ | ✅ | ❌ |
247
+ | checkEncryptionSecret | ✅ | ✅ | ✅ | ❌ |
248
+ | initWebStore | ❌ | ❌ | ❌ | ✅ |
249
+ | saveToStore | ❌ | ❌ | ❌ | ✅ |
250
+ | getNCDatabasePath | ✅ | ✅ | ❌ | ❌ |
251
+ | createNCConnection | ✅ | ✅ | ❌ | ❌ |
252
+ | closeNCConnection | ✅ | ✅ | ❌ | ❌ |
253
+ | isNCDatabase | ✅ | ✅ | ❌ | ❌ |
254
+ | transaction | ✅ | ✅ | ✅ | ✅ |
255
+ | getFromHTTPRequest | ✅ | ✅ | ✅ | ✅ | since 4.2.0 |
256
+ | isDatabaseEncrypted | ✅ | ✅ | ✅ | ❌ | since 4.6.2-2 |
257
+ | isInConfigEncryption | ✅ | ✅ | ✅ | ❌ | since 4.6.2-2 |
258
+ | isInConfigBiometricAuth | ✅ | ✅ | ❌ | ❌ | since 4.6.2-2 |
259
+ | getFromLocalDiskToStore | ❌ | ❌ | ❌ | ✅ | since 4.6.3 |
260
+ | saveToLocalDisk | ❌ | ❌ | ❌ | ✅ | since 4.6.3 |
261
+ | beginTransaction | ✅ | ✅ | ✅ | ✅ | since 5.0.7 |
262
+ | commitTransaction | ✅ | ✅ | ✅ | ✅ | since 5.0.7 |
263
+ | rollbackTransaction | ✅ | ✅ | ✅ | ✅ | since 5.0.7 |
264
+ | isTransactionActive | ✅ | ✅ | ✅ | ✅ | since 5.0.7 |
289
265
 
290
266
 
291
267
  ## Documentation & APIs
@@ -450,3 +426,7 @@ l1ndch"><img src="https://avatars.githubusercontent.com/u/170952278?v=4" width="
450
426
  <!-- ALL-CONTRIBUTORS-LIST:END -->
451
427
 
452
428
  This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
429
+
430
+ ## Credits
431
+
432
+ A big thank you to [Jean Pierre Quéau](https://github.com/jepiqueau), who maintained this plugin until version 6.0.0.
@@ -66,5 +66,5 @@ dependencies {
66
66
  //security library
67
67
  implementation "androidx.security:security-crypto:1.1.0-alpha06"
68
68
  implementation "androidx.biometric:biometric:1.1.0"
69
- annotationProcessor 'androidx.room:room-compiler:2.5.1'
69
+ annotationProcessor 'androidx.room:room-compiler:2.6.1'
70
70
  }
@@ -146,17 +146,15 @@ public class CapacitorSQLitePlugin extends Plugin {
146
146
  oldpassphrase = call.getString("oldpassphrase");
147
147
  if (implementation != null) {
148
148
  getActivity()
149
- .runOnUiThread(
150
- () -> {
151
- try {
152
- implementation.changeEncryptionSecret(call, passphrase, oldpassphrase);
153
- rHandler.retResult(call, null, null);
154
- } catch (Exception e) {
155
- String msg = "ChangeEncryptionSecret: " + e.getMessage();
156
- rHandler.retResult(call, null, msg);
157
- }
149
+ .runOnUiThread(() -> {
150
+ try {
151
+ implementation.changeEncryptionSecret(call, passphrase, oldpassphrase);
152
+ rHandler.retResult(call, null, null);
153
+ } catch (Exception e) {
154
+ String msg = "ChangeEncryptionSecret: " + e.getMessage();
155
+ rHandler.retResult(call, null, msg);
158
156
  }
159
- );
157
+ });
160
158
  } else {
161
159
  rHandler.retResult(call, null, loadMessage);
162
160
  }
@@ -1535,12 +1533,10 @@ public class CapacitorSQLitePlugin extends Plugin {
1535
1533
  getActivity().runOnUiThread(() -> rHandler.retResult(call, null, null));
1536
1534
  } catch (Exception e) {
1537
1535
  getActivity()
1538
- .runOnUiThread(
1539
- () -> {
1540
- String msg = "GetFromHTTPRequest: " + e.getMessage();
1541
- rHandler.retResult(call, null, msg);
1542
- }
1543
- );
1536
+ .runOnUiThread(() -> {
1537
+ String msg = "GetFromHTTPRequest: " + e.getMessage();
1538
+ rHandler.retResult(call, null, msg);
1539
+ });
1544
1540
  }
1545
1541
  };
1546
1542
  Thread myHttpThread = new Thread(setHTTPRunnable);
@@ -763,7 +763,7 @@ public class Database {
763
763
  String substring = suffix.substring(returningIndex + "returning".length());
764
764
  String names = substring.trim();
765
765
  retObj.put("names", getNames(names));
766
- }
766
+ }
767
767
  }
768
768
  return retObj;
769
769
  }
@@ -786,6 +786,7 @@ public class Database {
786
786
  }
787
787
  return input.substring(0, minIndex).trim();
788
788
  }
789
+
789
790
  private JSObject isReturning(String sqlStmt) {
790
791
  JSObject retObj = new JSObject();
791
792
 
@@ -12,7 +12,6 @@ import com.getcapacitor.community.database.sqlite.SQLite.UtilsSQLite;
12
12
  import java.util.ArrayList;
13
13
  import java.util.HashMap;
14
14
  import java.util.Map;
15
-
16
15
  import org.json.JSONArray;
17
16
  import org.json.JSONException;
18
17
  import org.json.JSONObject;
@@ -397,10 +396,10 @@ public class ImportFromJson {
397
396
  }
398
397
  if (isBlob(tColTypes)) {
399
398
  // Old process flow
400
- oldProcessFow(mDb, values, tableName,tColNames, tColTypes, mode);
399
+ oldProcessFow(mDb, values, tableName, tColNames, tColTypes, mode);
401
400
  } else {
402
401
  // New process flow
403
- newProcessFlow(mDb, values, tableName,tColNames);
402
+ newProcessFlow(mDb, values, tableName, tColNames);
404
403
  }
405
404
  } catch (JSONException e) {
406
405
  throw new Exception("CreateTableData: " + e.getMessage());
@@ -420,13 +419,17 @@ public class ImportFromJson {
420
419
  * @param mode
421
420
  * @throws Exception
422
421
  */
423
- private void oldProcessFow( Database mDb, ArrayList<ArrayList<Object>> values,
424
- String tableName, ArrayList<String> tColNames,
425
- ArrayList<String> tColTypes, String mode) throws Exception {
422
+ private void oldProcessFow(
423
+ Database mDb,
424
+ ArrayList<ArrayList<Object>> values,
425
+ String tableName,
426
+ ArrayList<String> tColNames,
427
+ ArrayList<String> tColTypes,
428
+ String mode
429
+ ) throws Exception {
426
430
  try {
427
431
  // Loop on table's value
428
432
  for (int j = 0; j < values.size(); j++) {
429
-
430
433
  // Check the row number of columns
431
434
  ArrayList<Object> row = createRowValues(values.get(j));
432
435
  //
@@ -452,8 +455,8 @@ public class ImportFromJson {
452
455
  throw new Exception("oldProcessFlow: " + e.getMessage());
453
456
  }
454
457
  }
455
- private ArrayList<Object> createRowValues(ArrayList<Object> row )
456
- throws Exception {
458
+
459
+ private ArrayList<Object> createRowValues(ArrayList<Object> row) throws Exception {
457
460
  try {
458
461
  // Iterate over the ArrayList and check for JSONArray objects
459
462
  for (int i = 0; i < row.size(); i++) {
@@ -472,6 +475,7 @@ public class ImportFromJson {
472
475
  throw new Exception("createRowValues: " + e.getMessage());
473
476
  }
474
477
  }
478
+
475
479
  private byte[] jsonArrayToByteArray(JSONArray jsonArray) throws JSONException {
476
480
  byte[] byteArray = new byte[jsonArray.length()];
477
481
  for (int i = 0; i < jsonArray.length(); i++) {
@@ -488,21 +492,21 @@ public class ImportFromJson {
488
492
  * @param tColNames
489
493
  * @throws Exception
490
494
  */
491
- private void newProcessFlow(Database mDb, ArrayList<ArrayList<Object>> values,
492
- String tableName, ArrayList<String> tColNames) throws Exception {
495
+ private void newProcessFlow(Database mDb, ArrayList<ArrayList<Object>> values, String tableName, ArrayList<String> tColNames)
496
+ throws Exception {
493
497
  try {
494
498
  JSONObject retObjStrs = generateInsertAndDeletedStrings(tColNames, values);
495
499
  // Create the statement for INSERT
496
500
  String namesString = _uJson.convertToString(tColNames, ',');
497
501
  if (retObjStrs.has("insert")) {
498
502
  String stmtInsert = new StringBuilder("INSERT OR REPLACE INTO ")
499
- .append(tableName)
500
- .append("(")
501
- .append(namesString)
502
- .append(") ")
503
- .append(retObjStrs.get("insert"))
504
- .append(";")
505
- .toString();
503
+ .append(tableName)
504
+ .append("(")
505
+ .append(namesString)
506
+ .append(") ")
507
+ .append(retObjStrs.get("insert"))
508
+ .append(";")
509
+ .toString();
506
510
  JSObject retObj = mDb.prepareSQL(stmtInsert, new ArrayList<>(), true, "no");
507
511
  long lastId = retObj.getLong("lastId");
508
512
  if (lastId < 0) {
@@ -511,13 +515,13 @@ public class ImportFromJson {
511
515
  }
512
516
  if (retObjStrs.has("delete")) {
513
517
  String stmtDelete = new StringBuilder("DELETE FROM ")
514
- .append(tableName)
515
- .append(" WHERE ")
516
- .append(tColNames.get(0))
517
- .append(" ")
518
- .append(retObjStrs.get("delete"))
519
- .append(";")
520
- .toString();
518
+ .append(tableName)
519
+ .append(" WHERE ")
520
+ .append(tColNames.get(0))
521
+ .append(" ")
522
+ .append(retObjStrs.get("delete"))
523
+ .append(";")
524
+ .toString();
521
525
  JSObject retObj = mDb.prepareSQL(stmtDelete, new ArrayList<>(), true, "no");
522
526
  long lastId = retObj.getLong("lastId");
523
527
  if (lastId < 0) {
@@ -546,6 +550,7 @@ public class ImportFromJson {
546
550
  }
547
551
  return containsBlob;
548
552
  }
553
+
549
554
  /**
550
555
  * Create the Row Statement to load the data
551
556
  * @param mDb
@@ -558,13 +563,13 @@ public class ImportFromJson {
558
563
  * @return
559
564
  */
560
565
  private String createRowStatement(
561
- Database mDb,
562
- ArrayList<String> tColNames,
563
- ArrayList<String> tColTypes,
564
- ArrayList<Object> row,
565
- int j,
566
- String tableName,
567
- String mode
566
+ Database mDb,
567
+ ArrayList<String> tColNames,
568
+ ArrayList<String> tColTypes,
569
+ ArrayList<Object> row,
570
+ int j,
571
+ String tableName,
572
+ String mode
568
573
  ) throws Exception {
569
574
  String msg = "CreateRowStatement: ";
570
575
  msg += "Table" + tableName + " values row";
@@ -583,15 +588,15 @@ public class ImportFromJson {
583
588
  throw new Exception(msg + j + "questionMarkString is empty");
584
589
  }
585
590
  stmt =
586
- new StringBuilder("INSERT INTO ")
587
- .append(tableName)
588
- .append("(")
589
- .append(namesString)
590
- .append(")")
591
- .append(" VALUES (")
592
- .append(questionMarkString)
593
- .append(");")
594
- .toString();
591
+ new StringBuilder("INSERT INTO ")
592
+ .append(tableName)
593
+ .append("(")
594
+ .append(namesString)
595
+ .append(")")
596
+ .append(" VALUES (")
597
+ .append(questionMarkString)
598
+ .append(");")
599
+ .toString();
595
600
  } else {
596
601
  Boolean isUpdate = true;
597
602
  Integer idxDelete = tColNames.indexOf("sql_deleted");
@@ -601,10 +606,10 @@ public class ImportFromJson {
601
606
  isUpdate = false;
602
607
  Object key = tColNames.get(0);
603
608
  StringBuilder sbQuery = new StringBuilder("DELETE FROM ")
604
- .append(tableName)
605
- .append(" WHERE ")
606
- .append(tColNames.get(0))
607
- .append(" = ");
609
+ .append(tableName)
610
+ .append(" WHERE ")
611
+ .append(tColNames.get(0))
612
+ .append(" = ");
608
613
 
609
614
  if (key instanceof Integer) sbQuery.append(row.get(0)).append(";");
610
615
  if (key instanceof String) sbQuery.append("'").append(row.get(0)).append("';");
@@ -619,12 +624,12 @@ public class ImportFromJson {
619
624
  }
620
625
  Object key = tColNames.get(0);
621
626
  StringBuilder sbQuery = new StringBuilder("UPDATE ")
622
- .append(tableName)
623
- .append(" SET ")
624
- .append(setString)
625
- .append(" WHERE ")
626
- .append(tColNames.get(0))
627
- .append(" = ");
627
+ .append(tableName)
628
+ .append(" SET ")
629
+ .append(setString)
630
+ .append(" WHERE ")
631
+ .append(tColNames.get(0))
632
+ .append(" = ");
628
633
 
629
634
  if (key instanceof Integer) sbQuery.append(row.get(0)).append(";");
630
635
  if (key instanceof String) sbQuery.append("'").append(row.get(0)).append("';");
@@ -646,12 +651,12 @@ public class ImportFromJson {
646
651
  * @throws Exception
647
652
  */
648
653
  private Boolean checkUpdate(
649
- Database mDb,
650
- String stmt,
651
- ArrayList<Object> values,
652
- String tableName,
653
- ArrayList<String> tColNames,
654
- ArrayList<String> tColTypes
654
+ Database mDb,
655
+ String stmt,
656
+ ArrayList<Object> values,
657
+ String tableName,
658
+ ArrayList<String> tColNames,
659
+ ArrayList<String> tColTypes
655
660
  ) throws Exception {
656
661
  Boolean isRun = true;
657
662
  if (stmt.substring(0, 6).equals("UPDATE")) {
@@ -677,6 +682,7 @@ public class ImportFromJson {
677
682
  }
678
683
  return isRun;
679
684
  }
685
+
680
686
  /**
681
687
  * Check Values
682
688
  * @param values
@@ -740,20 +746,18 @@ public class ImportFromJson {
740
746
  ", ",
741
747
  rowIndex
742
748
  .stream()
743
- .map(
744
- item -> {
745
- if (item instanceof String) {
746
- String val = (String) item;
747
- String rVal = val;
748
- if (val.contains("'")) {
749
- rVal = val.replace("'", "''");
750
- }
751
- return "'" + rVal + "'";
752
- } else {
753
- return item.toString();
749
+ .map(item -> {
750
+ if (item instanceof String) {
751
+ String val = (String) item;
752
+ String rVal = val;
753
+ if (val.contains("'")) {
754
+ rVal = val.replace("'", "''");
754
755
  }
756
+ return "'" + rVal + "'";
757
+ } else {
758
+ return item.toString();
755
759
  }
756
- )
760
+ })
757
761
  .toArray(String[]::new)
758
762
  );
759
763
  insertValues.append("(").append(formattedRow).append("), ");
@@ -1,17 +1,17 @@
1
1
  package com.getcapacitor.community.database.sqlite.SQLite;
2
2
 
3
- import java.net.MalformedURLException;
4
3
  import android.content.Context;
5
4
  import java.io.File;
6
5
  import java.io.FileOutputStream;
7
6
  import java.io.IOException;
8
7
  import java.io.InputStream;
9
8
  import java.net.HttpURLConnection;
9
+ import java.net.MalformedURLException;
10
10
  import java.net.URL;
11
- import java.util.regex.Matcher;
12
- import java.util.regex.Pattern;
13
11
  import java.net.URLDecoder;
14
12
  import java.nio.charset.StandardCharsets;
13
+ import java.util.regex.Matcher;
14
+ import java.util.regex.Pattern;
15
15
 
16
16
  public class UtilsDownloadFromHTTP {
17
17
 
@@ -20,14 +20,14 @@ public class UtilsDownloadFromHTTP {
20
20
  private final UtilsFile _uFile = new UtilsFile();
21
21
 
22
22
  public void download(Context context, String fileUrl) throws Exception {
23
- Boolean isZip = false;
23
+ Boolean isZip = false;
24
24
  String fileName = "";
25
25
  try {
26
26
  String[] fileDetails = getFileDetails(fileUrl);
27
27
  fileName = fileDetails[0];
28
28
  String extension = fileDetails[1];
29
29
  if (!fileName.contains("SQLite.db")) {
30
- switch(extension) {
30
+ switch (extension) {
31
31
  case "db":
32
32
  fileName = fileName.substring(0, fileName.length() - 3) + "SQLite.db";
33
33
  break;
@@ -38,12 +38,10 @@ public class UtilsDownloadFromHTTP {
38
38
  throw new Exception("Unknown file type. Filename: " + fileName);
39
39
  }
40
40
  }
41
-
42
41
  } catch (Exception e) {
43
42
  throw new Exception(e.getMessage());
44
43
  }
45
44
 
46
-
47
45
  File cacheDir = context.getCacheDir();
48
46
  String cachePath = cacheDir.getAbsolutePath();
49
47
  String tmpFilePath = cachePath + File.separator + fileName;
@@ -75,15 +73,16 @@ public class UtilsDownloadFromHTTP {
75
73
  String decodedPath = URLDecoder.decode(path, StandardCharsets.UTF_8.toString()); // Decode URL-encoded path
76
74
  String filename = decodedPath.substring(decodedPath.lastIndexOf('/') + 1); // Extract filename from decoded path
77
75
  String extension = getFileExtension(filename);
78
- if(extension == null) {
76
+ if (extension == null) {
79
77
  throw new Exception("extension db or zip not found");
80
78
  }
81
- return new String[]{filename, extension};
79
+ return new String[] { filename, extension };
82
80
  } catch (MalformedURLException e) {
83
81
  e.printStackTrace();
84
82
  throw new Exception(e.getMessage());
85
83
  }
86
84
  }
85
+
87
86
  public static String getFileExtension(String filename) {
88
87
  Pattern pattern = Pattern.compile("\\.([a-zA-Z0-9]+)(?:[\\?#]|$)");
89
88
  Matcher matcher = pattern.matcher(filename);
@@ -94,6 +93,7 @@ public class UtilsDownloadFromHTTP {
94
93
 
95
94
  return null; // no extension found
96
95
  }
96
+
97
97
  public static void downloadFileToCache(String fileURL, String fileName, String cacheDir) throws Exception {
98
98
  HttpURLConnection httpConn = null;
99
99
  try {
@@ -113,9 +113,10 @@ public class UtilsDownloadFromHTTP {
113
113
  // create temporary file path
114
114
  String tmpFilePath = cacheDir + File.separator + dbName;
115
115
  // opens input stream from the HTTP connection
116
- try (InputStream inputStream = httpConn.getInputStream();
117
- FileOutputStream outputStream = new FileOutputStream(tmpFilePath)) {
118
-
116
+ try (
117
+ InputStream inputStream = httpConn.getInputStream();
118
+ FileOutputStream outputStream = new FileOutputStream(tmpFilePath)
119
+ ) {
119
120
  byte[] buffer = new byte[1024];
120
121
  int bytesRead;
121
122
  while ((bytesRead = inputStream.read(buffer)) != -1) {
@@ -850,9 +850,7 @@ export class SQLiteDBConnection {
850
850
  throw new Error('Error a task.statement must be provided');
851
851
  }
852
852
  if ('values' in task && task.values && task.values.length > 0) {
853
- const retMode = task.statement.toUpperCase().includes('RETURNING')
854
- ? 'all'
855
- : 'no';
853
+ const retMode = task.statement.toUpperCase().includes('RETURNING') ? 'all' : 'no';
856
854
  const ret = await this.sqlite.run({
857
855
  database: this.dbName,
858
856
  statement: task.statement,