@capacitor-community/sqlite 4.6.3 → 5.0.0-beta.1

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
@@ -1,8 +1,8 @@
1
1
  <p align="center"><br><img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" /></p>
2
2
  <h3 align="center">SQLITE DATABASE</h3>
3
- <p align="center"><strong><code>@capacitor-community/sqlite</code></strong></p>
3
+ <p align="center"><strong><code>@capacitor-community/sqlite@next</code></strong></p>
4
4
  <br>
5
- <p align="center" style="font-size:50px;color:red"><strong>CAPACITOR 4</strong></p><br>
5
+ <p align="center" style="font-size:50px;color:red"><strong>CAPACITOR 5</strong></p><br>
6
6
 
7
7
  <p align="center">
8
8
  Capacitor community plugin for Native and Electron SQLite Databases. In Native databases could be encrypted with SQLCipher
@@ -30,17 +30,17 @@
30
30
  To install:
31
31
 
32
32
  ```
33
- npm install --save @capacitor-community/sqlite
33
+ npm install --save @capacitor-community/sqlite@next
34
34
  npx cap sync
35
35
  ```
36
36
 
37
37
  ```
38
- yarn add @capacitor-community/sqlite
38
+ yarn add @capacitor-community/sqlite@next
39
39
  npx cap sync
40
40
  ```
41
41
 
42
42
  ```
43
- pnpm install --save @capacitor-community/sqlite
43
+ pnpm install --save @capacitor-community/sqlite@next
44
44
  pnpm install --save @jeep-sqlite
45
45
  pnpm install --save sql.js
46
46
  npx cap sync
@@ -11,20 +11,21 @@ buildscript {
11
11
  mavenCentral()
12
12
  }
13
13
  dependencies {
14
- classpath 'com.android.tools.build:gradle:7.2.2'
14
+ classpath 'com.android.tools.build:gradle:7.4.1'
15
15
  }
16
16
  }
17
17
 
18
18
  apply plugin: 'com.android.library'
19
19
 
20
20
  android {
21
- compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 32
21
+ namespace "com.getcapacitor.community.database.sqlite"
22
+ compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
22
23
  packagingOptions {
23
24
  exclude 'build-data.properties'
24
25
  }
25
26
  defaultConfig {
26
27
  minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
27
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 32
28
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
28
29
  versionCode 1
29
30
  versionName "1.0"
30
31
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -50,20 +51,27 @@ repositories {
50
51
  mavenCentral()
51
52
  }
52
53
 
54
+ gradle.projectsEvaluated {
55
+ tasks.withType(JavaCompile) {
56
+ options.compilerArgs << "-Xlint:deprecation"
57
+ options.compilerArgs << "-Xlint:unchecked"
58
+ }
59
+ }
53
60
 
54
61
  dependencies {
55
62
  implementation fileTree(dir: 'libs', include: ['*.jar'])
56
63
  implementation project(':capacitor-android')
57
64
  implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
58
- implementation 'androidx.room:room-runtime:2.5.0'
65
+ implementation 'androidx.room:room-runtime:2.5.1'
59
66
  testImplementation "junit:junit:$junitVersion"
60
67
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
61
68
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
62
69
  implementation "androidx.coordinatorlayout:coordinatorlayout:1.2.0"
63
70
  implementation 'net.zetetic:android-database-sqlcipher:4.5.3'
64
- implementation "androidx.sqlite:sqlite:2.3.0"
71
+ implementation "androidx.sqlite:sqlite:2.3.1"
65
72
  //security library
66
73
  implementation "androidx.security:security-crypto:1.1.0-alpha05"
67
74
  implementation "androidx.biometric:biometric:1.1.0"
68
- annotationProcessor 'androidx.room:room-compiler:2.5.0'
75
+ annotationProcessor 'androidx.room:room-compiler:2.5.1'
69
76
  }
77
+
@@ -1,3 +1,3 @@
1
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
- package="com.getcapacitor.community.database.sqlite">
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
3
3
  </manifest>
@@ -555,6 +555,11 @@ public class CapacitorSQLitePlugin extends Plugin {
555
555
  return;
556
556
  }
557
557
  JSArray openModes = call.getArray("openModes");
558
+ if (dbNames == null || openModes == null) {
559
+ String msg = "CheckConnectionsConsistency: No dbNames or openModes given";
560
+ rHandler.retResult(call, null, msg);
561
+ return;
562
+ }
558
563
  if (implementation != null) {
559
564
  try {
560
565
  Boolean res = implementation.checkConnectionsConsistency(dbNames, openModes);
@@ -784,10 +789,15 @@ public class CapacitorSQLitePlugin extends Plugin {
784
789
  folderPath = call.getString("folderPath");
785
790
  }
786
791
  if (!call.getData().has("dbNameList")) {
787
- dbList = new JSArray();
792
+ dbList = null;
788
793
  } else {
789
794
  dbList = call.getArray("dbNameList");
790
795
  }
796
+ if (dbList == null) {
797
+ String msg = "AddSQLiteSuffix: dbNameList not given or empty";
798
+ rHandler.retResult(call, null, msg);
799
+ return;
800
+ }
791
801
  if (implementation != null) {
792
802
  try {
793
803
  implementation.addSQLiteSuffix(folderPath, dbList);
@@ -818,10 +828,15 @@ public class CapacitorSQLitePlugin extends Plugin {
818
828
  folderPath = call.getString("folderPath");
819
829
  }
820
830
  if (!call.getData().has("dbNameList")) {
821
- dbList = new JSArray();
831
+ dbList = null;
822
832
  } else {
823
833
  dbList = call.getArray("dbNameList");
824
834
  }
835
+ if (dbList == null) {
836
+ String msg = "deleteOldDatabases: dbNameList not given or empty";
837
+ rHandler.retResult(call, null, msg);
838
+ return;
839
+ }
825
840
  if (implementation != null) {
826
841
  try {
827
842
  implementation.deleteOldDatabases(folderPath, dbList);
@@ -852,10 +867,15 @@ public class CapacitorSQLitePlugin extends Plugin {
852
867
  folderPath = call.getString("folderPath");
853
868
  }
854
869
  if (!call.getData().has("dbNameList")) {
855
- dbList = new JSArray();
870
+ dbList = null;
856
871
  } else {
857
872
  dbList = call.getArray("dbNameList");
858
873
  }
874
+ if (dbList == null) {
875
+ String msg = "moveDatabasesAndAddSuffix: dbNameList not given or empty";
876
+ rHandler.retResult(call, null, msg);
877
+ return;
878
+ }
859
879
  if (implementation != null) {
860
880
  try {
861
881
  implementation.moveDatabasesAndAddSuffix(folderPath, dbList);
@@ -936,6 +956,11 @@ public class CapacitorSQLitePlugin extends Plugin {
936
956
  return;
937
957
  }
938
958
  JSArray set = call.getArray("set");
959
+ if (set == null) {
960
+ String msg = "ExecuteSet: Must provide a set of SQL statements";
961
+ rHandler.retChanges(call, retRes, msg);
962
+ return;
963
+ }
939
964
  if (set.length() == 0) {
940
965
  String msg = "ExecuteSet: Must provide a non-empty set of SQL statements";
941
966
  rHandler.retChanges(call, retRes, msg);
@@ -999,7 +1024,11 @@ public class CapacitorSQLitePlugin extends Plugin {
999
1024
  return;
1000
1025
  }
1001
1026
  JSArray values = call.getArray("values");
1002
-
1027
+ if (values == null) {
1028
+ String msg = "Run: Must provide an Array of values";
1029
+ rHandler.retChanges(call, retRes, msg);
1030
+ return;
1031
+ }
1003
1032
  Boolean transaction = call.getBoolean("transaction", true);
1004
1033
  Boolean readOnly = call.getBoolean("readonly", false);
1005
1034
  if (implementation != null) {
@@ -1044,6 +1073,11 @@ public class CapacitorSQLitePlugin extends Plugin {
1044
1073
  return;
1045
1074
  }
1046
1075
  JSArray values = call.getArray("values");
1076
+ if (values == null) {
1077
+ String msg = "Query: Must provide an Array of values";
1078
+ rHandler.retValues(call, new JSArray(), msg);
1079
+ return;
1080
+ }
1047
1081
  Boolean readOnly = call.getBoolean("readonly", false);
1048
1082
  if (implementation != null) {
1049
1083
  try {
@@ -1263,7 +1297,7 @@ public class CapacitorSQLitePlugin extends Plugin {
1263
1297
  if (!call.getData().has("database")) {
1264
1298
  String msg = "GetSyncDate : Must provide a database name";
1265
1299
  retRes.put("changes", Integer.valueOf(-1));
1266
- rHandler.retSyncDate(call, new Long(0), msg);
1300
+ rHandler.retSyncDate(call, Long.valueOf(0), msg);
1267
1301
  return;
1268
1302
  }
1269
1303
  String dbName = call.getString("database");
@@ -1275,11 +1309,11 @@ public class CapacitorSQLitePlugin extends Plugin {
1275
1309
  return;
1276
1310
  } catch (Exception e) {
1277
1311
  String msg = "GetSyncDate: " + e.getMessage();
1278
- rHandler.retSyncDate(call, new Long(0), msg);
1312
+ rHandler.retSyncDate(call, Long.valueOf(0), msg);
1279
1313
  return;
1280
1314
  }
1281
1315
  } else {
1282
- rHandler.retSyncDate(call, new Long(0), loadMessage);
1316
+ rHandler.retSyncDate(call, Long.valueOf(0), loadMessage);
1283
1317
  return;
1284
1318
  }
1285
1319
  }
@@ -1304,6 +1338,11 @@ public class CapacitorSQLitePlugin extends Plugin {
1304
1338
  return;
1305
1339
  }
1306
1340
  JSArray upgrade = call.getArray("upgrade");
1341
+ if (upgrade == null) {
1342
+ String msg = "AddUpgradeStatement: Must provide an array with upgrade statement";
1343
+ rHandler.retResult(call, null, msg);
1344
+ return;
1345
+ }
1307
1346
 
1308
1347
  if (implementation != null) {
1309
1348
  try {
@@ -380,8 +380,18 @@ public class ImportFromJson {
380
380
  if (tableNamesTypes.length() == 0) {
381
381
  throw new Exception("CreateTableData: no column names & types returned");
382
382
  }
383
- ArrayList<String> tColNames = (ArrayList<String>) tableNamesTypes.get("names");
384
- ArrayList<String> tColTypes = (ArrayList<String>) tableNamesTypes.get("types");
383
+ ArrayList<String> tColNames = new ArrayList<>();
384
+ ArrayList<String> tColTypes = new ArrayList<>();
385
+ if (tableNamesTypes.has("names")) {
386
+ tColNames = _uJson.getColumnNames(tableNamesTypes.get("names"));
387
+ } else {
388
+ throw new Exception("GetValues: Table " + tableName + " no names");
389
+ }
390
+ if (tableNamesTypes.has("types")) {
391
+ tColTypes = _uJson.getColumnNames(tableNamesTypes.get("types"));
392
+ } else {
393
+ throw new Exception("GetValues: Table " + tableName + " no types");
394
+ }
385
395
 
386
396
  // Loop on Table's Values
387
397
  for (int j = 0; j < values.size(); j++) {
@@ -6,8 +6,11 @@ import com.getcapacitor.community.database.sqlite.SQLite.Database;
6
6
  import com.getcapacitor.community.database.sqlite.SQLite.UtilsDrop;
7
7
  import java.sql.Blob;
8
8
  import java.util.ArrayList;
9
+ import java.util.Arrays;
9
10
  import java.util.Iterator;
10
11
  import java.util.List;
12
+
13
+ import org.json.JSONArray;
11
14
  import org.json.JSONException;
12
15
  import org.json.JSONObject;
13
16
 
@@ -34,8 +37,14 @@ public class UtilsJson {
34
37
  List<String> tables = _uDrop.getTablesNames(db);
35
38
  for (String tableName : tables) {
36
39
  JSObject namesTypes = getTableColumnNamesTypes(db, tableName);
37
- ArrayList<String> colNames = (ArrayList<String>) namesTypes.get("names");
38
- if (colNames.contains("last_modified")) {
40
+ ArrayList<String> colNames = new ArrayList<>();
41
+ if (namesTypes.has("names")) {
42
+ colNames = getColumnNames(namesTypes.get("names"));
43
+ } else {
44
+ throw new Exception("isLastModified: Table " + tableName + " no names");
45
+ }
46
+
47
+ if (colNames.size() > 0 && colNames.contains("last_modified")) {
39
48
  ret = true;
40
49
  break;
41
50
  }
@@ -46,6 +55,18 @@ public class UtilsJson {
46
55
  }
47
56
  }
48
57
 
58
+ /**
59
+ * Get Column name's list
60
+ * @param obj
61
+ * @return
62
+ */
63
+ public ArrayList<String> getColumnNames(Object obj) {
64
+
65
+ ArrayList<String> colNames = new ArrayList<>();
66
+ if (obj instanceof ArrayList) colNames = (ArrayList<String>) obj;
67
+
68
+ return colNames;
69
+ }
49
70
  /**
50
71
  * Check existence of sql_deleted column
51
72
  * @param db
@@ -61,7 +82,12 @@ public class UtilsJson {
61
82
  List<String> tables = _uDrop.getTablesNames(db);
62
83
  for (String tableName : tables) {
63
84
  JSObject namesTypes = getTableColumnNamesTypes(db, tableName);
64
- ArrayList<String> colNames = (ArrayList<String>) namesTypes.get("names");
85
+ ArrayList<String> colNames = new ArrayList<>();
86
+ if (namesTypes.has("names")) {
87
+ colNames = getColumnNames(namesTypes.get("names"));
88
+ } else {
89
+ throw new Exception("isSqlDeleted: Table " + tableName + " no names");
90
+ }
65
91
  if (colNames.contains("sql_deleted")) {
66
92
  ret = true;
67
93
  break;
@@ -469,15 +495,15 @@ public class UtilsJson {
469
495
  ArrayList<ArrayList<Object>> values = new ArrayList<>();
470
496
  try {
471
497
  JSObject tableNamesTypes = getTableColumnNamesTypes(mDb, tableName);
472
- ArrayList<String> rowNames = new ArrayList<>();
473
498
  ArrayList<String> rowTypes = new ArrayList<>();
499
+ ArrayList<String> rowNames = new ArrayList<>();
474
500
  if (tableNamesTypes.has("names")) {
475
- rowNames = (ArrayList<String>) tableNamesTypes.get("names");
501
+ rowNames = getColumnNames(tableNamesTypes.get("names"));
476
502
  } else {
477
503
  throw new Exception("GetValues: Table " + tableName + " no names");
478
504
  }
479
505
  if (tableNamesTypes.has("types")) {
480
- rowTypes = (ArrayList<String>) tableNamesTypes.get("types");
506
+ rowTypes = getColumnNames(tableNamesTypes.get("types"));
481
507
  } else {
482
508
  throw new Exception("GetValues: Table " + tableName + " no types");
483
509
  }
@@ -84,15 +84,18 @@ public class UtilsSQLite {
84
84
  }
85
85
 
86
86
  private String[] dealWithTriggers(String[] sqlCmdArray) {
87
- List listArray = Arrays.asList(sqlCmdArray);
87
+ List<String> listArray = Arrays.asList(sqlCmdArray);
88
88
  listArray = trimArray(listArray);
89
89
  listArray = concatRemoveEnd(listArray);
90
- String[] retArray = (String[]) listArray.toArray(new String[0]);
90
+ Object[] objectList = listArray.toArray();
91
+ String[] retArray = Arrays.copyOf(objectList, objectList.length, String[].class);
92
+
93
+ // String[] retArray = listArray.toArray(new String[listArray.size()]);
91
94
  return retArray;
92
95
  }
93
96
 
94
- private List concatRemoveEnd(List listArray) {
95
- List lArray = new ArrayList(listArray);
97
+ private List<String> concatRemoveEnd(List<String> listArray) {
98
+ List<String> lArray = new ArrayList<String>(listArray);
96
99
  if (lArray.contains("END")) {
97
100
  int idx = lArray.indexOf("END");
98
101
  lArray.set(idx - 1, lArray.get(idx - 1) + "; END");
@@ -103,11 +106,12 @@ public class UtilsSQLite {
103
106
  }
104
107
  }
105
108
 
106
- private List trimArray(List listArray) {
107
- for (int i = 0; i < listArray.size(); i++) {
108
- listArray.set(i, listArray.get(i).toString().trim());
109
+ private List<String> trimArray(List<String> listArray) {
110
+ List<String> trimmedStrings = new ArrayList<String>();
111
+ for(String s : listArray) {
112
+ trimmedStrings.add(s.trim());
109
113
  }
110
- return listArray;
114
+ return trimmedStrings;
111
115
  }
112
116
 
113
117
  public ArrayList<Object> objectJSArrayToArrayList(JSArray jsArray) throws JSONException {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor-community/sqlite",
3
- "version": "4.6.3",
3
+ "version": "5.0.0-beta.1",
4
4
  "description": "Community plugin for native & electron SQLite databases",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -56,11 +56,11 @@
56
56
  "prepublishOnly": "npm run build && npm run build-electron && npm run docgen"
57
57
  },
58
58
  "devDependencies": {
59
- "@capacitor/android": "^4.6.3",
60
- "@capacitor/cli": "^4.6.3",
61
- "@capacitor/core": "^4.6.3",
59
+ "@capacitor/android": "^5.0.0-beta.1",
60
+ "@capacitor/cli": "^5.0.0-beta.1",
61
+ "@capacitor/core": "^5.0.0-beta.1",
62
62
  "@capacitor/docgen": "^0.0.17",
63
- "@capacitor/ios": "^4.6.3",
63
+ "@capacitor/ios": "^5.0.0-beta.1",
64
64
  "@ionic/eslint-config": "^0.3.0",
65
65
  "@ionic/prettier-config": "^1.0.1",
66
66
  "@ionic/swiftlint-config": "^1.1.2",
@@ -76,7 +76,7 @@
76
76
  "typescript": "~4.1.5"
77
77
  },
78
78
  "peerDependencies": {
79
- "@capacitor/core": "^4.0.0"
79
+ "@capacitor/core": "^5.0.0-beta.1"
80
80
  },
81
81
  "prettier": "@ionic/prettier-config",
82
82
  "swiftlint": "@ionic/swiftlint-config",
package/src/web.ts CHANGED
@@ -78,7 +78,7 @@ export class CapacitorSQLiteWeb
78
78
  this.notifyListeners('sqliteSaveDatabaseToDiskEvent', event.detail);
79
79
  },
80
80
  );
81
-
81
+
82
82
  if (!this.isWebStoreOpen) {
83
83
  this.isWebStoreOpen = await this.jeepSqliteElement.isStoreOpen();
84
84
  }