@capacitor-community/sqlite 3.3.2 → 3.3.3-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/CHANGELOG.md +14 -0
- package/README.md +6 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +83 -7
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +101 -3
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/RetHandler.java +24 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +67 -47
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/JsonIndex.java +5 -4
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsFile.java +9 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsNCDatabase.java +26 -0
- package/dist/esm/definitions.d.ts +111 -2
- package/dist/esm/definitions.js +63 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +5 -1
- package/dist/esm/web.js +16 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +79 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +79 -0
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +17 -1
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +85 -8
- package/ios/Plugin/CapacitorSQLitePlugin.m +4 -0
- package/ios/Plugin/CapacitorSQLitePlugin.swift +111 -0
- package/ios/Plugin/Database.swift +39 -22
- package/ios/Plugin/ImportExportJson/ImportFromJson.swift +2 -1
- package/ios/Plugin/ImportExportJson/JsonSQLite.swift +1 -1
- package/ios/Plugin/ReturnHandler.swift +13 -0
- package/ios/Plugin/Utils/UtilsNCDatabase.swift +31 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## 3.3.3-1 (2021-12-18)
|
|
2
|
+
|
|
3
|
+
### Added Features
|
|
4
|
+
|
|
5
|
+
- Open in Read-Only Mode databases without SQLite suffix
|
|
6
|
+
- getNCDatabasePath, createNCConnection, closeNCConnection, isNCDatabase
|
|
7
|
+
- add NonConformedDatabase.md documentation
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
- fix mode "UNIQUE" not case sensitive in importToJson index issue#203
|
|
12
|
+
- fix support non-conformed database in read-only mode issue#201
|
|
13
|
+
|
|
14
|
+
|
|
1
15
|
## 3.3.2 (2021-12-13)
|
|
2
16
|
|
|
3
17
|
### Chore
|
package/README.md
CHANGED
|
@@ -212,6 +212,10 @@ No configuration required for this plugin
|
|
|
212
212
|
| changeEncryptionSecret | ✅ | ✅ | ❌ | ❌ |
|
|
213
213
|
| initWebStore | ❌ | ❌ | ❌ | ✅ |
|
|
214
214
|
| saveToStore | ❌ | ❌ | ❌ | ✅ |
|
|
215
|
+
| getNCDatabasePath | ✅ | ✅ | ❌ | ❌ |
|
|
216
|
+
| createNCConnection | ✅ | ✅ | ❌ | ❌ |
|
|
217
|
+
| closeNCConnection | ✅ | ✅ | ❌ | ❌ |
|
|
218
|
+
| isNCDatabase | ✅ | ✅ | ❌ | ❌ |
|
|
215
219
|
|
|
216
220
|
## Supported SQLite Types
|
|
217
221
|
|
|
@@ -237,6 +241,8 @@ No configuration required for this plugin
|
|
|
237
241
|
|
|
238
242
|
- [Web_Documentation](https://github.com/capacitor-community/sqlite/blob/master/docs/Web-Usage.md)
|
|
239
243
|
|
|
244
|
+
- [Non_Conformed_Databases_Documentation](https://github.com/capacitor-community/sqlite/blob/master/docs/NonConformedDatabases.md)
|
|
245
|
+
|
|
240
246
|
### Framework's Usage
|
|
241
247
|
|
|
242
248
|
- [Ionic/Angular_Usage_Documentation](https://github.com/capacitor-community/sqlite/blob/master/docs/Ionic-Angular-Usage.md)
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java
CHANGED
|
@@ -14,6 +14,7 @@ import com.getcapacitor.community.database.sqlite.SQLite.ImportExportJson.JsonSQ
|
|
|
14
14
|
import com.getcapacitor.community.database.sqlite.SQLite.ImportExportJson.UtilsJson;
|
|
15
15
|
import com.getcapacitor.community.database.sqlite.SQLite.UtilsFile;
|
|
16
16
|
import com.getcapacitor.community.database.sqlite.SQLite.UtilsMigrate;
|
|
17
|
+
import com.getcapacitor.community.database.sqlite.SQLite.UtilsNCDatabase;
|
|
17
18
|
import com.getcapacitor.community.database.sqlite.SQLite.UtilsSQLite;
|
|
18
19
|
import com.getcapacitor.community.database.sqlite.SQLite.UtilsSecret;
|
|
19
20
|
import java.io.File;
|
|
@@ -39,6 +40,7 @@ public class CapacitorSQLite {
|
|
|
39
40
|
private UtilsFile uFile = new UtilsFile();
|
|
40
41
|
private UtilsJson uJson = new UtilsJson();
|
|
41
42
|
private UtilsMigrate uMigrate = new UtilsMigrate();
|
|
43
|
+
private UtilsNCDatabase uNCDatabase = new UtilsNCDatabase();
|
|
42
44
|
private UtilsSecret uSecret;
|
|
43
45
|
private SharedPreferences sharedPreferences;
|
|
44
46
|
|
|
@@ -116,6 +118,15 @@ public class CapacitorSQLite {
|
|
|
116
118
|
}
|
|
117
119
|
}
|
|
118
120
|
|
|
121
|
+
public String getNCDatabasePath(String folderPath, String database) throws Exception {
|
|
122
|
+
try {
|
|
123
|
+
String databasePath = uNCDatabase.getNCDatabasePath(context, folderPath, database);
|
|
124
|
+
return databasePath;
|
|
125
|
+
} catch (Exception e) {
|
|
126
|
+
throw new Exception(e.getMessage());
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
119
130
|
/**
|
|
120
131
|
* CreateConnection
|
|
121
132
|
* @param dbName
|
|
@@ -148,6 +159,38 @@ public class CapacitorSQLite {
|
|
|
148
159
|
}
|
|
149
160
|
}
|
|
150
161
|
|
|
162
|
+
/**
|
|
163
|
+
* CreateConnection
|
|
164
|
+
* @param dbPath
|
|
165
|
+
* @param version
|
|
166
|
+
* @throws Exception
|
|
167
|
+
*/
|
|
168
|
+
public void createNCConnection(String dbPath, int version) throws Exception {
|
|
169
|
+
// check if connection already exists
|
|
170
|
+
Database conn = dbDict.get(dbPath);
|
|
171
|
+
if (conn != null) {
|
|
172
|
+
String msg = "Connection " + dbPath + " already exists";
|
|
173
|
+
throw new Exception(msg);
|
|
174
|
+
}
|
|
175
|
+
try {
|
|
176
|
+
Boolean isDBPathExists = uFile.isPathExists(dbPath);
|
|
177
|
+
if (!isDBPathExists) {
|
|
178
|
+
String msg = "Database " + dbPath + " does not exist";
|
|
179
|
+
throw new Exception(msg);
|
|
180
|
+
}
|
|
181
|
+
Database db = new Database(context, dbPath, false, "no-encryption", version, new Hashtable<>(), sharedPreferences);
|
|
182
|
+
if (db != null) {
|
|
183
|
+
dbDict.put(dbPath, db);
|
|
184
|
+
return;
|
|
185
|
+
} else {
|
|
186
|
+
String msg = "db is null";
|
|
187
|
+
throw new Exception(msg);
|
|
188
|
+
}
|
|
189
|
+
} catch (Exception e) {
|
|
190
|
+
throw new Exception(e.getMessage());
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
151
194
|
/**
|
|
152
195
|
* Open
|
|
153
196
|
* @param dbName
|
|
@@ -222,6 +265,29 @@ public class CapacitorSQLite {
|
|
|
222
265
|
}
|
|
223
266
|
}
|
|
224
267
|
|
|
268
|
+
/**
|
|
269
|
+
* CloseNCConnection
|
|
270
|
+
* @param dbPath
|
|
271
|
+
* @throws Exception
|
|
272
|
+
*/
|
|
273
|
+
public void closeNCConnection(String dbPath) throws Exception {
|
|
274
|
+
Database db = dbDict.get(dbPath);
|
|
275
|
+
if (db != null) {
|
|
276
|
+
if (db.isOpen()) {
|
|
277
|
+
try {
|
|
278
|
+
close(dbPath);
|
|
279
|
+
} catch (Exception e) {
|
|
280
|
+
throw new Exception(e.getMessage());
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
dbDict.remove(dbPath);
|
|
284
|
+
return;
|
|
285
|
+
} else {
|
|
286
|
+
String msg = "No available connection for database " + dbPath;
|
|
287
|
+
throw new Exception(msg);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
225
291
|
/**
|
|
226
292
|
* CloseConnection
|
|
227
293
|
* @param dbName
|
|
@@ -301,6 +367,16 @@ public class CapacitorSQLite {
|
|
|
301
367
|
return uFile.isFileExists(context, dbName + "SQLite.db");
|
|
302
368
|
}
|
|
303
369
|
|
|
370
|
+
/**
|
|
371
|
+
* IsNCDatabase
|
|
372
|
+
* @param dbPath
|
|
373
|
+
* @return Boolean
|
|
374
|
+
* @throws Exception
|
|
375
|
+
*/
|
|
376
|
+
public Boolean isNCDatabase(String dbPath) {
|
|
377
|
+
return uFile.isPathExists(dbPath);
|
|
378
|
+
}
|
|
379
|
+
|
|
304
380
|
/**
|
|
305
381
|
* IsTableExists
|
|
306
382
|
* @param dbName
|
|
@@ -398,7 +474,7 @@ public class CapacitorSQLite {
|
|
|
398
474
|
dbName = getDatabaseName(dbName);
|
|
399
475
|
Database db = dbDict.get(dbName);
|
|
400
476
|
if (db != null) {
|
|
401
|
-
if (db.isOpen()) {
|
|
477
|
+
if (!db.isNCDB() && db.isOpen()) {
|
|
402
478
|
// convert string in string[]
|
|
403
479
|
String[] sqlCmdArray = uSqlite.getStatementsArray(statements);
|
|
404
480
|
try {
|
|
@@ -428,7 +504,7 @@ public class CapacitorSQLite {
|
|
|
428
504
|
dbName = getDatabaseName(dbName);
|
|
429
505
|
Database db = dbDict.get(dbName);
|
|
430
506
|
if (db != null) {
|
|
431
|
-
if (db.isOpen()) {
|
|
507
|
+
if (!db.isNCDB() && db.isOpen()) {
|
|
432
508
|
try {
|
|
433
509
|
JSObject res = db.executeSet(set, transaction);
|
|
434
510
|
return res;
|
|
@@ -458,7 +534,7 @@ public class CapacitorSQLite {
|
|
|
458
534
|
dbName = getDatabaseName(dbName);
|
|
459
535
|
Database db = dbDict.get(dbName);
|
|
460
536
|
if (db != null) {
|
|
461
|
-
if (db.isOpen()) {
|
|
537
|
+
if (!db.isNCDB() && db.isOpen()) {
|
|
462
538
|
if (values.length() > 0) {
|
|
463
539
|
try {
|
|
464
540
|
ArrayList<Object> arrValues = uSqlite.objectJSArrayToArrayList(values);
|
|
@@ -737,11 +813,11 @@ public class CapacitorSQLite {
|
|
|
737
813
|
|
|
738
814
|
private String getDatabaseName(String dbName) {
|
|
739
815
|
String retName = dbName;
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
816
|
+
if (!retName.contains("/")) {
|
|
817
|
+
if (retName.endsWith(".db")) {
|
|
818
|
+
retName = retName.substring(0, retName.length() - 3);
|
|
819
|
+
}
|
|
743
820
|
}
|
|
744
|
-
|
|
745
821
|
return retName;
|
|
746
822
|
}
|
|
747
823
|
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java
CHANGED
|
@@ -132,6 +132,60 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
@PluginMethod
|
|
136
|
+
public void getNCDatabasePath(PluginCall call) {
|
|
137
|
+
String folderPath = null;
|
|
138
|
+
String dbName = null;
|
|
139
|
+
if (!call.getData().has("path")) {
|
|
140
|
+
String msg = "getNCDatabasePath: Must provide a folder path";
|
|
141
|
+
rHandler.retPath(call, null, msg);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
folderPath = call.getString("path");
|
|
145
|
+
if (!call.getData().has("database")) {
|
|
146
|
+
String msg = "getNCDatabasePath: Must provide a database name";
|
|
147
|
+
rHandler.retPath(call, null, msg);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
dbName = call.getString("database");
|
|
151
|
+
try {
|
|
152
|
+
String databasePath = implementation.getNCDatabasePath(folderPath, dbName);
|
|
153
|
+
rHandler.retPath(call, databasePath, null);
|
|
154
|
+
return;
|
|
155
|
+
} catch (Exception e) {
|
|
156
|
+
String msg = "getNCDatabasePath: " + e.getMessage();
|
|
157
|
+
rHandler.retResult(call, null, msg);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* CreateNCConnection Method
|
|
164
|
+
* Create a non-conformed connection to a database
|
|
165
|
+
* @param call
|
|
166
|
+
*/
|
|
167
|
+
@PluginMethod
|
|
168
|
+
public void createNCConnection(PluginCall call) {
|
|
169
|
+
String dbPath = null;
|
|
170
|
+
int dbVersion = Integer.valueOf(-1);
|
|
171
|
+
if (!call.getData().has("databasePath")) {
|
|
172
|
+
String msg = "CreateNCConnection: Must provide a database path";
|
|
173
|
+
rHandler.retResult(call, null, msg);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
dbPath = call.getString("databasePath");
|
|
177
|
+
dbVersion = call.getInt("version", 1);
|
|
178
|
+
try {
|
|
179
|
+
implementation.createNCConnection(dbPath, dbVersion);
|
|
180
|
+
rHandler.retResult(call, null, null);
|
|
181
|
+
return;
|
|
182
|
+
} catch (Exception e) {
|
|
183
|
+
String msg = "CreateNCConnection: " + e.getMessage();
|
|
184
|
+
rHandler.retResult(call, null, msg);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
135
189
|
/**
|
|
136
190
|
* CreateConnection Method
|
|
137
191
|
* Create a connection to a database
|
|
@@ -141,8 +195,6 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
141
195
|
public void createConnection(PluginCall call) {
|
|
142
196
|
String dbName = null;
|
|
143
197
|
int dbVersion = Integer.valueOf(-1);
|
|
144
|
-
String secret = null;
|
|
145
|
-
String newsecret = null;
|
|
146
198
|
String inMode = null;
|
|
147
199
|
JSObject ret = new JSObject();
|
|
148
200
|
if (!call.getData().has("database")) {
|
|
@@ -166,7 +218,6 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
166
218
|
}
|
|
167
219
|
} else {
|
|
168
220
|
inMode = "no-encryption";
|
|
169
|
-
secret = "";
|
|
170
221
|
}
|
|
171
222
|
Dictionary<Integer, JSONObject> upgDict = versionUpgrades.get(dbName);
|
|
172
223
|
try {
|
|
@@ -252,6 +303,30 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
252
303
|
}
|
|
253
304
|
}
|
|
254
305
|
|
|
306
|
+
/**
|
|
307
|
+
* CloseNCConnection Method
|
|
308
|
+
* Close a non-conformed database connection
|
|
309
|
+
* @param call
|
|
310
|
+
*/
|
|
311
|
+
@PluginMethod
|
|
312
|
+
public void closeNCConnection(PluginCall call) {
|
|
313
|
+
if (!call.getData().has("databasePath")) {
|
|
314
|
+
String msg = "CloseNCConnection: Must provide a database path";
|
|
315
|
+
rHandler.retResult(call, null, msg);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
String dbPath = call.getString("databasePath");
|
|
319
|
+
try {
|
|
320
|
+
implementation.closeNCConnection(dbPath);
|
|
321
|
+
rHandler.retResult(call, null, null);
|
|
322
|
+
return;
|
|
323
|
+
} catch (Exception e) {
|
|
324
|
+
String msg = "CloseNCConnection: " + e.getMessage();
|
|
325
|
+
rHandler.retResult(call, null, msg);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
255
330
|
/**
|
|
256
331
|
* CloseConnection Method
|
|
257
332
|
* Close the connection to a database
|
|
@@ -323,6 +398,29 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
323
398
|
}
|
|
324
399
|
}
|
|
325
400
|
|
|
401
|
+
/**
|
|
402
|
+
* IsDatabase Method
|
|
403
|
+
* Check if the database file exists
|
|
404
|
+
* @param call
|
|
405
|
+
*/
|
|
406
|
+
@PluginMethod
|
|
407
|
+
public void isNCDatabase(PluginCall call) {
|
|
408
|
+
if (!call.getData().has("databasePath")) {
|
|
409
|
+
rHandler.retResult(call, null, "Must provide a database path");
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
String dbPath = call.getString("databasePath");
|
|
413
|
+
try {
|
|
414
|
+
Boolean res = implementation.isNCDatabase(dbPath);
|
|
415
|
+
rHandler.retResult(call, res, null);
|
|
416
|
+
return;
|
|
417
|
+
} catch (Exception e) {
|
|
418
|
+
String msg = "isNCDatabase: " + e.getMessage();
|
|
419
|
+
rHandler.retResult(call, null, msg);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
326
424
|
/**
|
|
327
425
|
* IsTableExists Method
|
|
328
426
|
* Check if a table exists in a database
|
|
@@ -140,4 +140,28 @@ public class RetHandler {
|
|
|
140
140
|
return;
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* RetPath Method
|
|
146
|
+
* Create and return the capSQLiteResult object
|
|
147
|
+
* @param call
|
|
148
|
+
* @param res
|
|
149
|
+
* @param message
|
|
150
|
+
*/
|
|
151
|
+
public void retPath(PluginCall call, String res, String message) {
|
|
152
|
+
JSObject ret = new JSObject();
|
|
153
|
+
if (message != null) {
|
|
154
|
+
ret.put("message", message);
|
|
155
|
+
Log.v(TAG, "*** ERROR " + message);
|
|
156
|
+
call.reject(message);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (res != null) {
|
|
160
|
+
ret.put("path", res);
|
|
161
|
+
call.resolve(ret);
|
|
162
|
+
return;
|
|
163
|
+
} else {
|
|
164
|
+
call.resolve();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
143
167
|
}
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java
CHANGED
|
@@ -58,6 +58,7 @@ public class Database {
|
|
|
58
58
|
private Dictionary<Integer, JSONObject> _vUpgObject = new Hashtable<>();
|
|
59
59
|
private ImportFromJson fromJson = new ImportFromJson();
|
|
60
60
|
private ExportToJson toJson = new ExportToJson();
|
|
61
|
+
private Boolean ncDB = false;
|
|
61
62
|
|
|
62
63
|
public Database(
|
|
63
64
|
Context context,
|
|
@@ -75,7 +76,12 @@ public class Database {
|
|
|
75
76
|
this._version = version;
|
|
76
77
|
this._vUpgObject = vUpgObject;
|
|
77
78
|
this._sharedPreferences = sharedPreferences;
|
|
78
|
-
|
|
79
|
+
if (dbName.contains("/") && dbName.endsWith("SQLite.db")) {
|
|
80
|
+
this.ncDB = true;
|
|
81
|
+
this._file = new File(dbName);
|
|
82
|
+
} else {
|
|
83
|
+
this._file = this._context.getDatabasePath(dbName);
|
|
84
|
+
}
|
|
79
85
|
this._globVar = new GlobalSQLite();
|
|
80
86
|
this._uSqlite = new UtilsSQLite();
|
|
81
87
|
this._uCipher = new UtilsSQLCipher();
|
|
@@ -104,12 +110,20 @@ public class Database {
|
|
|
104
110
|
|
|
105
111
|
/**
|
|
106
112
|
* isOpen Method
|
|
107
|
-
* @return database
|
|
113
|
+
* @return database status
|
|
108
114
|
*/
|
|
109
115
|
public Boolean isOpen() {
|
|
110
116
|
return _isOpen;
|
|
111
117
|
}
|
|
112
118
|
|
|
119
|
+
/**
|
|
120
|
+
* isNCDB Method
|
|
121
|
+
* @return non-conformed database status
|
|
122
|
+
*/
|
|
123
|
+
public Boolean isNCDB() {
|
|
124
|
+
return ncDB;
|
|
125
|
+
}
|
|
126
|
+
|
|
113
127
|
/**
|
|
114
128
|
* Open method
|
|
115
129
|
* @return open status
|
|
@@ -128,7 +142,11 @@ public class Database {
|
|
|
128
142
|
}
|
|
129
143
|
}
|
|
130
144
|
try {
|
|
131
|
-
|
|
145
|
+
if (!isNCDB()) {
|
|
146
|
+
_db = SQLiteDatabase.openOrCreateDatabase(_file, password, null);
|
|
147
|
+
} else {
|
|
148
|
+
_db = SQLiteDatabase.openDatabase(String.valueOf(_file), "", null, SQLiteDatabase.OPEN_READONLY);
|
|
149
|
+
}
|
|
132
150
|
if (_db != null) {
|
|
133
151
|
if (_db.isOpen()) {
|
|
134
152
|
// set the Foreign Key Pragma ON
|
|
@@ -141,60 +159,62 @@ public class Database {
|
|
|
141
159
|
_db = null;
|
|
142
160
|
throw new Exception(msg);
|
|
143
161
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (curVersion == 0) {
|
|
147
|
-
_db.setVersion(1);
|
|
162
|
+
if (!isNCDB()) {
|
|
163
|
+
try {
|
|
148
164
|
curVersion = _db.getVersion();
|
|
165
|
+
if (curVersion == 0) {
|
|
166
|
+
_db.setVersion(1);
|
|
167
|
+
curVersion = _db.getVersion();
|
|
168
|
+
}
|
|
169
|
+
} catch (IllegalStateException e) {
|
|
170
|
+
String msg = "Failed in get/setVersion " + e.getMessage();
|
|
171
|
+
Log.v(TAG, msg);
|
|
172
|
+
close();
|
|
173
|
+
_db = null;
|
|
174
|
+
throw new Exception(msg);
|
|
175
|
+
} catch (SQLiteException e) {
|
|
176
|
+
String msg = "Failed in setVersion " + e.getMessage();
|
|
177
|
+
Log.v(TAG, msg);
|
|
178
|
+
close();
|
|
179
|
+
_db = null;
|
|
180
|
+
throw new Exception(msg);
|
|
149
181
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
boolean ret = _uFile.deleteBackupDB(_context, _dbName);
|
|
168
|
-
if (!ret) {
|
|
169
|
-
String msg = "Failed in deleteBackupDB backup-\" + _dbName";
|
|
182
|
+
if (_version > curVersion) {
|
|
183
|
+
if (_vUpgObject.size() > 0) {
|
|
184
|
+
try {
|
|
185
|
+
_uUpg.onUpgrade(this, _context, _dbName, _vUpgObject, curVersion, _version);
|
|
186
|
+
boolean ret = _uFile.deleteBackupDB(_context, _dbName);
|
|
187
|
+
if (!ret) {
|
|
188
|
+
String msg = "Failed in deleteBackupDB backup-\" + _dbName";
|
|
189
|
+
Log.v(TAG, msg);
|
|
190
|
+
close();
|
|
191
|
+
_db = null;
|
|
192
|
+
throw new Exception(msg);
|
|
193
|
+
}
|
|
194
|
+
} catch (Exception e) {
|
|
195
|
+
// restore DB
|
|
196
|
+
boolean ret = _uFile.restoreDatabase(_context, _dbName);
|
|
197
|
+
String msg = e.getMessage();
|
|
198
|
+
if (!ret) msg += "Failed in restoreDatabase " + _dbName;
|
|
170
199
|
Log.v(TAG, msg);
|
|
171
200
|
close();
|
|
172
201
|
_db = null;
|
|
173
202
|
throw new Exception(msg);
|
|
174
203
|
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
} else {
|
|
186
|
-
try {
|
|
187
|
-
_db.setVersion(_version);
|
|
188
|
-
} catch (Exception e) {
|
|
189
|
-
String msg = e.getMessage() + "Failed in setting version " + _version;
|
|
190
|
-
close();
|
|
191
|
-
_db = null;
|
|
192
|
-
throw new Exception(msg);
|
|
204
|
+
} else {
|
|
205
|
+
try {
|
|
206
|
+
_db.setVersion(_version);
|
|
207
|
+
} catch (Exception e) {
|
|
208
|
+
String msg = e.getMessage() + "Failed in setting version " + _version;
|
|
209
|
+
close();
|
|
210
|
+
_db = null;
|
|
211
|
+
throw new Exception(msg);
|
|
212
|
+
}
|
|
193
213
|
}
|
|
194
214
|
}
|
|
215
|
+
_isOpen = true;
|
|
216
|
+
return;
|
|
195
217
|
}
|
|
196
|
-
_isOpen = true;
|
|
197
|
-
return;
|
|
198
218
|
} else {
|
|
199
219
|
_isOpen = false;
|
|
200
220
|
_db = null;
|
|
@@ -6,6 +6,7 @@ import java.util.ArrayList;
|
|
|
6
6
|
import java.util.Arrays;
|
|
7
7
|
import java.util.Iterator;
|
|
8
8
|
import java.util.List;
|
|
9
|
+
import java.util.Locale;
|
|
9
10
|
import org.json.JSONException;
|
|
10
11
|
import org.json.JSONObject;
|
|
11
12
|
|
|
@@ -40,8 +41,8 @@ public class JsonIndex {
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
public void setMode(String newMode) {
|
|
43
|
-
if (newMode.
|
|
44
|
-
this.mode = newMode;
|
|
44
|
+
if (newMode.equalsIgnoreCase("UNIQUE")) {
|
|
45
|
+
this.mode = newMode.toUpperCase();
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -49,7 +50,7 @@ public class JsonIndex {
|
|
|
49
50
|
ArrayList<String> retArray = new ArrayList<String>();
|
|
50
51
|
if (getName().length() > 0) retArray.add("name");
|
|
51
52
|
if (getValue().length() > 0) retArray.add("value");
|
|
52
|
-
if (getMode().length() > 0 && getMode().
|
|
53
|
+
if (getMode().length() > 0 && getMode().equalsIgnoreCase("UNIQUE")) retArray.add("mode");
|
|
53
54
|
return retArray;
|
|
54
55
|
}
|
|
55
56
|
|
|
@@ -76,7 +77,7 @@ public class JsonIndex {
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
if (key.equals("mode")) {
|
|
79
|
-
if (!(objValue instanceof String) || !(objValue.
|
|
80
|
+
if (!(objValue instanceof String) || !(((String) objValue).equalsIgnoreCase("UNIQUE"))) {
|
|
80
81
|
return false;
|
|
81
82
|
} else {
|
|
82
83
|
mode = (String) objValue;
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsFile.java
CHANGED
|
@@ -24,6 +24,15 @@ public class UtilsFile {
|
|
|
24
24
|
return file.exists();
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
public Boolean isPathExists(String filePath) {
|
|
28
|
+
File file = new File(filePath);
|
|
29
|
+
if (file.exists()) {
|
|
30
|
+
return true;
|
|
31
|
+
} else {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
27
36
|
public String[] getListOfFiles(Context context) {
|
|
28
37
|
String[] files = context.databaseList();
|
|
29
38
|
List<String> dbs = new ArrayList<>();
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsNCDatabase.java
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
package com.getcapacitor.community.database.sqlite.SQLite;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import java.io.File;
|
|
5
|
+
|
|
6
|
+
public class UtilsNCDatabase {
|
|
7
|
+
|
|
8
|
+
private static final String TAG = UtilsNCDatabase.class.getName();
|
|
9
|
+
private UtilsMigrate uMigrate = new UtilsMigrate();
|
|
10
|
+
|
|
11
|
+
public String getNCDatabasePath(Context context, String folderPath, String database) throws Exception {
|
|
12
|
+
String pathDB = new File(context.getFilesDir().getParentFile(), "databases").getAbsolutePath();
|
|
13
|
+
File dirDB = new File(pathDB);
|
|
14
|
+
if (!dirDB.isDirectory()) {
|
|
15
|
+
dirDB.mkdir();
|
|
16
|
+
}
|
|
17
|
+
String pathFiles = uMigrate.getFolder(context, folderPath);
|
|
18
|
+
// check if the path exists
|
|
19
|
+
File dir = new File(pathFiles);
|
|
20
|
+
if (!dir.exists()) {
|
|
21
|
+
throw new Exception("Folder " + dir + " does not exist");
|
|
22
|
+
}
|
|
23
|
+
String databasePath = pathFiles.concat("/").concat(database);
|
|
24
|
+
return databasePath;
|
|
25
|
+
}
|
|
26
|
+
}
|