cordova-sqlite-evmax-build-free 0.0.8 → 0.0.9

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.
@@ -12,6 +12,9 @@ import java.io.File;
12
12
 
13
13
  import java.lang.IllegalArgumentException;
14
14
 
15
+ import java.net.URI;
16
+ import java.net.URISyntaxException;
17
+
15
18
  import java.util.Map;
16
19
 
17
20
  import java.util.concurrent.BlockingQueue;
@@ -155,8 +158,11 @@ public class SQLitePlugin extends CordovaPlugin {
155
158
  case delete:
156
159
  o = args.getJSONObject(0);
157
160
  dbname = o.getString("path");
161
+ String dblocation = null;
162
+ if (o.has("androidDatabaseLocation"))
163
+ dblocation = o.getString("androidDatabaseLocation");
158
164
 
159
- deleteDatabase(dbname, cbc);
165
+ deleteDatabase(dbname, dblocation, cbc);
160
166
 
161
167
  break;
162
168
 
@@ -239,22 +245,37 @@ public class SQLitePlugin extends CordovaPlugin {
239
245
  this.cordova.getThreadPool().execute(r);
240
246
  }
241
247
  }
248
+
242
249
  /**
243
- * Open a database.
250
+ * Get a database file.
244
251
  *
245
252
  * @param dbName The name of the database file
246
253
  */
247
- private SQLiteNativeDatabase openDatabase(String dbname, boolean ignored, CallbackContext cbc, boolean old_impl, int dbid) throws Exception {
248
- try {
249
- // ASSUMPTION: no db (connection/handle) is already stored in the map
250
- // [should be true according to the code in DBRunner.run()]
251
-
254
+ private File getDatabaseFile(String dbname, String dblocation) throws URISyntaxException {
255
+ if (dblocation == null) {
252
256
  File dbfile = this.cordova.getActivity().getDatabasePath(dbname);
253
257
 
254
258
  if (!dbfile.exists()) {
255
259
  dbfile.getParentFile().mkdirs();
256
260
  }
257
261
 
262
+ return dbfile;
263
+ }
264
+
265
+ return new File(new File(new URI(dblocation)), dbname);
266
+ }
267
+
268
+ /**
269
+ * Open a database.
270
+ *
271
+ * @param dbName The name of the database file
272
+ */
273
+ private SQLiteNativeDatabase openDatabase(String dbname, String dblocation, CallbackContext cbc, boolean old_impl, int dbid) throws Exception {
274
+ try {
275
+ // ASSUMPTION: no db (connection/handle) is already stored in the map
276
+ // [should be true according to the code in DBRunner.run()]
277
+
278
+ File dbfile = getDatabaseFile(dbname, dblocation);
258
279
  Log.v("info", "Open sqlite db: " + dbfile.getAbsolutePath());
259
280
 
260
281
  SQLiteNativeDatabase mydb = new SQLiteNativeDatabase();
@@ -273,17 +294,12 @@ public class SQLitePlugin extends CordovaPlugin {
273
294
  }
274
295
  }
275
296
 
276
- private SQLiteAndroidDatabase openDatabase2(String dbname, boolean ignored, CallbackContext cbc, boolean old_impl) throws Exception {
297
+ private SQLiteAndroidDatabase openDatabase2(String dbname, String dblocation, CallbackContext cbc, boolean old_impl) throws Exception {
277
298
  try {
278
299
  // ASSUMPTION: no db (connection/handle) is already stored in the map
279
300
  // [should be true according to the code in DBRunner.run()]
280
301
 
281
- File dbfile = this.cordova.getActivity().getDatabasePath(dbname);
282
-
283
- if (!dbfile.exists()) {
284
- dbfile.getParentFile().mkdirs();
285
- }
286
-
302
+ File dbfile = getDatabaseFile(dbname, dblocation);
287
303
  Log.v("info", "Open sqlite db: " + dbfile.getAbsolutePath());
288
304
 
289
305
  SQLiteAndroidDatabase mydb = new SQLiteAndroidDatabase();
@@ -339,7 +355,7 @@ public class SQLitePlugin extends CordovaPlugin {
339
355
  }
340
356
  }
341
357
 
342
- private void deleteDatabase(String dbname, CallbackContext cbc) {
358
+ private void deleteDatabase(String dbname, String dblocation, CallbackContext cbc) {
343
359
  DBRunner r = dbrmap.get(dbname);
344
360
  if (r != null) {
345
361
  try {
@@ -351,7 +367,7 @@ public class SQLitePlugin extends CordovaPlugin {
351
367
  Log.e(SQLitePlugin.class.getSimpleName(), "couldn't close database", e);
352
368
  }
353
369
  } else {
354
- boolean deleteResult = this.deleteDatabaseNow(dbname);
370
+ boolean deleteResult = this.deleteDatabaseNow(dbname, dblocation);
355
371
  if (deleteResult) {
356
372
  cbc.success();
357
373
  } else {
@@ -367,10 +383,10 @@ public class SQLitePlugin extends CordovaPlugin {
367
383
  *
368
384
  * @return true if successful or false if an exception was encountered
369
385
  */
370
- private boolean deleteDatabaseNow(String dbname) {
371
- File dbfile = this.cordova.getActivity().getDatabasePath(dbname);
372
-
386
+ private boolean deleteDatabaseNow(String dbname, String dblocation) {
373
387
  try {
388
+ File dbfile = getDatabaseFile(dbname, dblocation);
389
+
374
390
  return cordova.getActivity().deleteDatabase(dbfile.getAbsolutePath());
375
391
  } catch (Exception e) {
376
392
  Log.e(SQLitePlugin.class.getSimpleName(), "couldn't delete database", e);
@@ -435,6 +451,7 @@ public class SQLitePlugin extends CordovaPlugin {
435
451
  private class DBRunner implements Runnable {
436
452
  final int dbid;
437
453
  final String dbname;
454
+ final String dblocation;
438
455
  // expose oldImpl:
439
456
  boolean oldImpl;
440
457
  private boolean bugWorkaround;
@@ -449,8 +466,20 @@ public class SQLitePlugin extends CordovaPlugin {
449
466
  this.dbid = dbid;
450
467
  this.dbname = dbname;
451
468
  this.oldImpl = options.has("androidOldDatabaseImplementation");
452
- Log.v(SQLitePlugin.class.getSimpleName(), "Android db implementation: built-in android.database.sqlite package");
469
+ //Log.v(SQLitePlugin.class.getSimpleName(), "Android db implementation: built-in android.database.sqlite package");
453
470
  this.bugWorkaround = this.oldImpl && options.has("androidBugWorkaround");
471
+
472
+ String mydblocation = null;
473
+ if (options.has("androidDatabaseLocation")) {
474
+ try {
475
+ mydblocation = options.getString("androidDatabaseLocation");
476
+ } catch (Exception e) {
477
+ // IGNORED
478
+ Log.e(SQLitePlugin.class.getSimpleName(), "unexpected JSON exception, IGNORED", e);
479
+ }
480
+ }
481
+ this.dblocation = mydblocation;
482
+
454
483
  if (this.bugWorkaround)
455
484
  Log.v(SQLitePlugin.class.getSimpleName(), "Android db closing/locking workaround applied");
456
485
 
@@ -461,9 +490,9 @@ public class SQLitePlugin extends CordovaPlugin {
461
490
  public void run() {
462
491
  try {
463
492
  if (!oldImpl)
464
- this.mydb = this.mydb1 = openDatabase(dbname, false, this.openCbc, this.oldImpl, this.dbid);
493
+ this.mydb = this.mydb1 = openDatabase(dbname, dblocation, this.openCbc, this.oldImpl, this.dbid);
465
494
  else
466
- this.mydb = openDatabase2(dbname, false, this.openCbc, this.oldImpl);
495
+ this.mydb = openDatabase2(dbname, dblocation, this.openCbc, this.oldImpl);
467
496
  } catch (Exception e) {
468
497
  Log.e(SQLitePlugin.class.getSimpleName(), "unexpected error, stopping db thread", e);
469
498
  dbrmap.remove(dbname);
@@ -526,7 +555,7 @@ public class SQLitePlugin extends CordovaPlugin {
526
555
  dbq.cbc.success();
527
556
  } else {
528
557
  try {
529
- boolean deleteResult = deleteDatabaseNow(dbname);
558
+ boolean deleteResult = deleteDatabaseNow(dbname, dblocation);
530
559
  if (deleteResult) {
531
560
  dbq.cbc.success();
532
561
  } else {