-
Notifications
You must be signed in to change notification settings - Fork 519
/
sqlite.core.js
833 lines (770 loc) · 22.6 KB
/
sqlite.core.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
/*
* sqlite.ios.core.js
*
* Created by Andrzej Porebski on 10/29/15.
* Copyright (c) 2015-2016 Andrzej Porebski.
*
* This software is largely based on the SQLLite Storage Cordova Plugin created by Chris Brody & Davide Bertola.
* The implementation was adopted and converted to use React Native bindings.
*
* See https://github.com/litehelpers/Cordova-sqlite-storage
*
* This library is available under the terms of the MIT License (2008).
* See http://opensource.org/licenses/alphabetical for full text.
*/
var NativeModules = require('react-native').NativeModules;
var DB_STATE_INIT, DB_STATE_OPEN, READ_ONLY_REGEX, SQLiteFactory, SQLitePlugin, SQLitePluginTransaction, argsArray, dblocations, newSQLError, nextTick, root, txLocks;
var plugin = {};
READ_ONLY_REGEX = /^(\s|;)*(?:alter|create|delete|drop|insert|reindex|replace|update)/i;
DB_STATE_INIT = "INIT";
DB_STATE_OPEN = "OPEN";
txLocks = {};
newSQLError = function(error, code) {
var sqlError;
sqlError = error;
if (!code) {
code = 0;
}
if (!sqlError) {
sqlError = new Error("a plugin had an error but provided no response");
sqlError.code = code;
}
if (typeof sqlError === "string") {
sqlError = new Error(error);
sqlError.code = code;
}
if (!sqlError.code && sqlError.message) {
sqlError.code = code;
}
if (!sqlError.code && !sqlError.message) {
sqlError = new Error("an unknown error was returned: " + JSON.stringify(sqlError));
sqlError.code = code;
}
return sqlError;
};
nextTick = window.setImmediate || function(fun) {
window.setTimeout(fun, 0);
};
/*
Utility that avoids leaking the arguments object. See
https://www.npmjs.org/package/argsarray
*/
argsArray = function(fun) {
return function() {
var args, i, len;
len = arguments.length;
if (len) {
args = [];
i = -1;
while (++i < len) {
args[i] = arguments[i];
}
return fun.call(this, args);
} else {
return fun.call(this, []);
}
};
};
plugin.exec = function(method, options, success, error) {
if (plugin.sqlitePlugin.DEBUG){
console.log('SQLite.' + method + '(' + JSON.stringify(options) + ')');
}
NativeModules["SQLite"][method](options,success,error);
};
SQLitePlugin = function(openargs, openSuccess, openError) {
var dbname;
if (!(openargs && openargs['name'])) {
throw newSQLError("Cannot create a SQLitePlugin db instance without a db name");
}
dbname = openargs.name;
if (typeof dbname !== 'string') {
throw newSQLError('sqlite plugin database name must be a string');
}
this.openargs = openargs;
this.dbname = dbname;
this.openSuccess = openSuccess;
this.openError = openError;
this.openSuccess || (this.openSuccess = function() {
console.log("DB opened: " + dbname);
});
this.openError || (this.openError = function(e) {
console.log(e.message);
});
this.open(this.openSuccess, this.openError);
};
SQLitePlugin.prototype.databaseFeatures = {
isSQLitePluginDatabase: true
};
SQLitePlugin.prototype.openDBs = {};
SQLitePlugin.prototype.addTransaction = function(t) {
if (!txLocks[this.dbname]) {
txLocks[this.dbname] = {
queue: [],
inProgress: false
};
}
txLocks[this.dbname].queue.push(t);
if (this.dbname in this.openDBs && this.openDBs[this.dbname] !== DB_STATE_INIT) {
this.startNextTransaction();
} else {
if (this.dbname in this.openDBs) {
console.log('new transaction is waiting for open operation');
} else {
console.log('database is closed, new transaction is [stuck] waiting until db is opened again!');
}
}
};
SQLitePlugin.prototype.transaction = function(fn, error, success) {
if (!this.openDBs[this.dbname]) {
error(newSQLError('database not open'));
return;
}
this.addTransaction(new SQLitePluginTransaction(this, fn, error, success, true, false));
};
SQLitePlugin.prototype.readTransaction = function(fn, error, success) {
if (!this.openDBs[this.dbname]) {
error(newSQLError('database not open'));
return;
}
this.addTransaction(new SQLitePluginTransaction(this, fn, error, success, false, true));
};
SQLitePlugin.prototype.startNextTransaction = function() {
var self;
self = this;
nextTick((function(_this) {
return function() {
var txLock;
if (!(_this.dbname in _this.openDBs) || _this.openDBs[_this.dbname] !== DB_STATE_OPEN) {
console.log('cannot start next transaction: database not open');
return;
}
txLock = txLocks[self.dbname];
if (!txLock) {
console.log('cannot start next transaction: database connection is lost');
} else if (txLock.queue.length > 0 && !txLock.inProgress) {
txLock.inProgress = true;
txLock.queue.shift().start();
}
};
})(this));
};
SQLitePlugin.prototype.abortAllPendingTransactions = function() {
var j, len1, ref, tx, txLock;
txLock = txLocks[this.dbname];
if (!!txLock && txLock.queue.length > 0) {
ref = txLock.queue;
for (j = 0, len1 = ref.length; j < len1; j++) {
tx = ref[j];
tx.abortFromQ(newSQLError('Invalid database handle'));
}
txLock.queue = [];
txLock.inProgress = false;
}
};
SQLitePlugin.prototype.sqlBatch = function(sqlStatements, success, error) {
var batchList, j, len1, myfn, st;
if (!sqlStatements || sqlStatements.constructor !== Array) {
throw newSQLError('sqlBatch expects an array');
}
batchList = [];
for (j = 0, len1 = sqlStatements.length; j < len1; j++) {
st = sqlStatements[j];
if (st.constructor === Array) {
if (st.length === 0) {
throw newSQLError('sqlBatch array element of zero (0) length');
}
batchList.push({
sql: st[0],
params: st.length === 0 ? [] : st[1]
});
} else {
batchList.push({
sql: st,
params: []
});
}
}
myfn = function(tx) {
var elem, k, len2, results;
results = [];
for (k = 0, len2 = batchList.length; k < len2; k++) {
elem = batchList[k];
results.push(tx.addStatement(elem.sql, elem.params, null, null));
}
return results;
};
let mysuccess = function() {
if (!!success) {
return success();
}
};
let myerror = function(e) {
if (!!error) {
return error(e);
} else {
console.log("Error handler not provided: ",e);
}
};
this.addTransaction(new SQLitePluginTransaction(this, myfn, myerror, mysuccess, true, false));
};
SQLitePlugin.prototype.open = function(success, error) {
var openerrorcb, opensuccesscb;
if (this.dbname in this.openDBs && this.openDBs[this.dbname] === DB_STATE_OPEN) {
console.log('database already open: ' + this.dbname);
nextTick((function(_this) {
return function() {
success(_this);
};
})(this));
} else {
console.log('OPEN database: ' + this.dbname);
opensuccesscb = (function(_this) {
return function() {
var txLock;
if (!_this.openDBs[_this.dbname]) {
console.log('database was closed during open operation');
}
if (_this.dbname in _this.openDBs) {
_this.openDBs[_this.dbname] = DB_STATE_OPEN;
}
if (!!success) {
success(_this);
}
txLock = txLocks[_this.dbname];
if (!!txLock && txLock.queue.length > 0 && !txLock.inProgress) {
_this.startNextTransaction();
}
};
})(this);
openerrorcb = (function(_this) {
return function() {
console.log('OPEN database: ' + _this.dbname + ' failed, aborting any pending transactions');
if (!!error) {
error(newSQLError('Could not open database'));
}
delete _this.openDBs[_this.dbname];
_this.abortAllPendingTransactions();
};
})(this);
this.openDBs[this.dbname] = DB_STATE_INIT;
plugin.exec("open",this.openargs,opensuccesscb, openerrorcb);
}
};
SQLitePlugin.prototype.close = function(success, error) {
if (this.dbname in this.openDBs) {
if (txLocks[this.dbname] && txLocks[this.dbname].inProgress) {
console.log('cannot close: transaction is in progress');
error(newSQLError('database cannot be closed while a transaction is in progress'));
return;
}
console.log('CLOSE database: ' + this.dbname);
delete this.openDBs[this.dbname];
if (txLocks[this.dbname]) {
console.log('closing db with transaction queue length: ' + txLocks[this.dbname].queue.length);
} else {
console.log('closing db with no transaction lock state');
}
let mysuccess = function(t, r) {
if (!!success) {
return success(r);
}
};
let myerror = function(t, e) {
if (!!error) {
return error(e);
} else {
console.log("Error handler not provided: ",e);
}
};
plugin.exec("close",{path: this.dbname}, mysuccess, myerror);
} else {
var err = 'cannot close: database is not open';
console.log(err);
if (error) {
nextTick(function() {
return error(err);
});
}
}
};
SQLitePlugin.prototype.attach = function(dbNameToAttach, dbAlias, success, error) {
if (this.dbname in this.openDBs) {
if (txLocks[this.dbname] && txLocks[this.dbname].inProgress) {
console.log('cannot attach: transaction is in progress');
error(newSQLError('database cannot be attached while a transaction is in progress'));
return;
}
console.log('ATTACH database ' + dbNameToAttach + ' to ' + this.dbname + ' with alias ' + dbAlias);
let mysuccess = function(t, r) {
if (!!success) {
return success(r);
}
};
let myerror = function(e) {
if (!!error) {
return error(e);
} else {
console.log("Error handler not provided: ",e);
}
};
plugin.exec("attach",{path: this.dbname, dbName: dbNameToAttach, dbAlias}, mysuccess, myerror);
} else {
let err = 'cannot attach: database is not open';
if (error) {
nextTick(function() {
return error(err);
});
}
}
};
SQLitePlugin.prototype.detach = function(dbAlias, success, error) {
if (this.dbname in this.openDBs) {
if (txLocks[this.dbname] && txLocks[this.dbname].inProgress) {
console.log('cannot attach: transaction is in progress');
error(newSQLError('database cannot be attached while a transaction is in progress'));
return;
}
console.log('DETACH database ' + dbAlias + ' from ' + this.dbname);
let mysuccess = function(t, r) {
if (!!success) {
return success(r);
}
};
let myerror = function(e) {
console.log('ERR', e);
if (!!error) {
return error(e);
} else {
console.log("Error handler not provided: ",e);
}
};
this.executeSql('DETACH DATABASE ' + dbAlias, [], mysuccess, myerror)
} else {
var err = 'cannot attach: database is not open';
console.log(err);
if (error) {
nextTick(function() {
return error(err);
});
}
}
};
SQLitePlugin.prototype.executeSql = function(statement, params, success, error) {
var myerror, myfn, mysuccess;
mysuccess = function(t, r) {
if (!!success) {
return success(r);
}
};
myerror = function(t, e) {
if (!!error) {
return error(e);
} else {
console.log("Error handler not provided: ",e);
}
};
myfn = function(tx) {
tx.addStatement(statement, params, mysuccess, myerror);
};
this.addTransaction(new SQLitePluginTransaction(this, myfn, null, null, false, false));
};
SQLitePluginTransaction = function(db, fn, error, success, txlock, readOnly) {
if (typeof fn !== "function") {
/*
This is consistent with the implementation in Chrome -- it
throws if you pass anything other than a function. This also
prevents us from stalling our txQueue if somebody passes a
false value for fn.
*/
let err = newSQLError("transaction expected a function");
if (!!error) {
return error(err);
} else {
throw err;
}
}
this.db = db;
this.fn = fn;
this.error = error;
this.success = success;
this.txlock = txlock;
this.readOnly = readOnly;
this.executes = [];
if (txlock) {
this.addStatement("BEGIN", [], null, function(tx, err) {
throw newSQLError("unable to begin transaction: " + err.message, err.code);
});
} else {
this.addStatement("SELECT 1", [], null, null);
}
};
SQLitePluginTransaction.prototype.start = function() {
var err;
try {
this.fn(this);
this.run();
} catch (_error) {
err = _error;
txLocks[this.db.dbname].inProgress = false;
this.db.startNextTransaction();
if (this.error) {
this.error(newSQLError(err));
}
}
};
SQLitePluginTransaction.prototype.executeSql = function(sql, values, success, error) {
var that = this;
if (that.finalized) {
throw {
message: 'InvalidStateError: DOM Exception 11: This transaction is already finalized. Transactions are committed' +
' after its success or failure handlers are called. If you are using a Promise to handle callbacks, be aware that' +
' implementations following the A+ standard adhere to run-to-completion semantics and so Promise resolution occurs' +
' on a subsequent tick and therefore after the transaction commits.',
code: 11
};
}
if (that.readOnly && READ_ONLY_REGEX.test(sql)) {
that.handleStatementFailure(error, {
message: 'invalid sql for a read-only transaction'
});
return;
}
let mysuccess = function(t, r) {
if (!!success) {
return success(t,r);
}
};
let myerror = function(t, e) {
if (!!error) {
return error(e);
} else {
console.log("Error handler not provided: ",e);
}
};
that.addStatement(sql, values, mysuccess, myerror);
};
SQLitePluginTransaction.prototype.addStatement = function(sql, values, success, error) {
var j, len1, params, sqlStatement, t, v;
sqlStatement = typeof sql === 'string' ? sql : sql.toString();
params = [];
if (!!values && values.constructor === Array) {
for (j = 0, len1 = values.length; j < len1; j++) {
v = values[j];
t = typeof v;
if (v === null || v === void 0 || t === 'number' || t === 'string'){
params.push(v);
} else if (t === 'boolean') {
//Convert true -> 1 / false -> 0
params.push(~~v);
}
else if (t !== 'function') {
params.push(v.toString());
console.warn('addStatement - parameter of type <'+t+'> converted to string using toString()')
} else {
let errorMsg = 'Unsupported parameter type <'+t+'> found in addStatement()';
console.error(errorMsg);
error(newSQLError(errorMsg));
return;
}
}
}
this.executes.push({
success: success,
error: error,
sql: sqlStatement,
params: params
});
};
SQLitePluginTransaction.prototype.handleStatementSuccess = function(handler, response) {
// console.log('handler response:',response,response.rows);
var payload, rows;
if (!handler) {
return;
}
rows = response.rows || [];
// console.log('handler rows now:',rows);
payload = {
rows: {
item: function(i) {
return rows[i];
},
/**
* non-standard Web SQL Database method to expose a copy of raw results
* @return {Array}
*/
raw: function() {
return rows.slice();
},
length: rows.length
},
rowsAffected: response.rowsAffected || 0,
insertId: response.insertId || void 0
};
// console.log('handler response payload:',payload);
handler(this, payload);
};
SQLitePluginTransaction.prototype.handleStatementFailure = function(handler, response) {
if (!handler) {
throw newSQLError("a statement with no error handler failed: " + response.message, response.code);
}
if (handler(this, response) !== false) {
throw newSQLError("a statement error callback did not return false: " + response.message, response.code);
}
};
SQLitePluginTransaction.prototype.run = function() {
var batchExecutes, handlerFor, i, callbacks, request, tropts, tx, txFailure, waiting;
txFailure = null;
tropts = [];
batchExecutes = this.executes;
waiting = batchExecutes.length;
this.executes = [];
tx = this;
handlerFor = function(index, didSucceed) {
return function(response) {
if (!txFailure) {
try {
if (didSucceed) {
tx.handleStatementSuccess(batchExecutes[index].success, response);
} else {
tx.handleStatementFailure(batchExecutes[index].error, newSQLError(response));
}
} catch (err) {
let errorMsg = JSON.stringify(err);
if(errorMsg === "{}") errorMsg = err.toString();
console.log("warning - exception while invoking a callback: " + errorMsg);
}
if (!didSucceed) {
txFailure = newSQLError(response);
}
}
if (--waiting === 0) {
if (txFailure) {
tx.executes = [];
tx.abort(txFailure);
} else if (tx.executes.length > 0) {
tx.run();
} else {
tx.finish();
}
}
};
};
i = 0;
callbacks = [];
while (i < batchExecutes.length) {
request = batchExecutes[i];
callbacks.push({
success: handlerFor(i, true),
error: handlerFor(i, false)
});
tropts.push({
qid: 1111,
sql: request.sql,
params: request.params
});
i++;
}
let mysuccess = function(result) {
var j, last, q, r, res, type;
if (result.length == 0){
return;
}
last = result.length - 1;
for (j = 0; j <= last; ++j) {
r = result[j];
type = r.type;
res = r.result;
q = callbacks[j];
if (q) {
if (q[type]) {
q[type](res);
}
}
}
};
var myerror = function(error) {
console.log("batch execution error: ",error);
};
plugin.exec("backgroundExecuteSqlBatch",{
dbargs: {
dbname: this.db.dbname
},
executes: tropts
}, mysuccess, myerror);
};
SQLitePluginTransaction.prototype.abort = function(txFailure) {
var failed, succeeded, tx;
if (this.finalized) {
return;
}
tx = this;
succeeded = function(tx) {
txLocks[tx.db.dbname].inProgress = false;
tx.db.startNextTransaction();
if (tx.error) {
tx.error(txFailure);
}
};
failed = function(tx, err) {
txLocks[tx.db.dbname].inProgress = false;
tx.db.startNextTransaction();
if (tx.error) {
tx.error(newSQLError("error while trying to roll back: " + err.message, err.code));
}
};
this.finalized = true;
if (this.txlock) {
this.addStatement("ROLLBACK", [], succeeded, failed);
this.run();
} else {
succeeded(tx);
}
};
SQLitePluginTransaction.prototype.finish = function() {
var failed, succeeded, tx;
if (this.finalized) {
return;
}
tx = this;
succeeded = function(tx) {
txLocks[tx.db.dbname].inProgress = false;
tx.db.startNextTransaction();
if (tx.success) {
tx.success();
}
};
failed = function(tx, err) {
txLocks[tx.db.dbname].inProgress = false;
tx.db.startNextTransaction();
if (tx.error) {
tx.error(newSQLError("error while trying to commit: " + err.message, err.code));
}
};
this.finalized = true;
if (this.txlock) {
this.addStatement("COMMIT", [], succeeded, failed);
this.run();
} else {
succeeded(tx);
}
};
SQLitePluginTransaction.prototype.abortFromQ = function(sqlerror) {
if (this.error) {
this.error(sqlerror);
}
};
dblocations = {
'default' : 'nosync',
'Documents' : 'docs',
'Library' : 'libs'
};
SQLiteFactory = function(){};
SQLiteFactory.prototype.DEBUG = function(debug) {
console.log("Setting debug to:",debug);
plugin.sqlitePlugin.DEBUG = debug;
};
SQLiteFactory.prototype.sqliteFeatures = function() {
return {
isSQLitePlugin: true
};
};
SQLiteFactory.prototype.openDatabase = argsArray(function(args) {
var errorcb, first, okcb, openargs, readOnly;
if (args.length < 1) {
return null;
}
first = args[0];
openargs = null;
okcb = errorcb = () => {};
if (first.constructor === String) {
openargs = {
name: first,
dblocation : dblocations['default']
};
if (args.length >= 5) {
okcb = args[4];
if (args.length > 5) {
errorcb = args[5];
}
}
} else {
openargs = first;
readOnly = !!openargs.readOnly;
if (!readOnly && (!openargs.location || openargs.location.constructor !== String || !dblocations.hasOwnProperty(openargs.location))) {
openargs.dblocation = dblocations['default'];
} else {
openargs.dblocation = dblocations[openargs.location];
}
if (!!openargs.createFromLocation) {
if (openargs.createFromLocation === 1) {
openargs.assetFilename = "1";
} else if (typeof openargs.createFromLocation == 'string'){
openargs.assetFilename = openargs.createFromLocation;
}
}
if (!!openargs.androidDatabaseImplementation && openargs.androidDatabaseImplementation === 2) {
openargs.androidOldDatabaseImplementation = 1;
}
if (!!openargs.androidLockWorkaround && openargs.androidLockWorkaround === 1) {
openargs.androidBugWorkaround = 1;
}
if (args.length >= 2) {
okcb = args[1];
if (args.length > 2) {
errorcb = args[2];
}
}
}
return new SQLitePlugin(openargs, okcb, errorcb);
});
SQLiteFactory.prototype.echoTest = function(success, error) {
let inputTestValue = 'test-string';
let mysuccess = function(testValue) {
if (testValue === inputTestValue) {
return success();
} else {
return error(`Mismatch: got: ${testValue} , expected: ${inputTestValue}`);
}
};
let myerror = function(e) {
return error(e);
};
plugin.exec("echoStringValue",{value: inputTestValue}, mysuccess, myerror);
};
SQLiteFactory.prototype.deleteDatabase = function(first,success, error) {
var args = {};
if (first.constructor === String) {
args.path = first;
args.dblocation = dblocations['default'];
} else {
if (!(first && first['name'])) {
throw new Error("Please specify db name via name property");
}
args.path = first.name;
if (!first.location || first.location.constructor !== String || !dblocations.hasOwnProperty(first.location)) {
args.dblocation = dblocations['default'];
} else {
args.dblocation = dblocations[first.location];
}
}
let mysuccess = function(r) {
delete SQLitePlugin.prototype.openDBs[args.path];
if (!!success) {
return success(r);
}
};
let myerror = function(e) {
if (!!error) {
return error(e);
} else {
console.log("deleteDatabase error handler not provided: ",e);
}
};
plugin.exec("delete",args,mysuccess,myerror);
};
plugin.sqlitePlugin = {
SQLiteFactory : SQLiteFactory,
SQLitePluginTransaction : SQLitePluginTransaction,
SQLitePlugin : SQLitePlugin
};
module.exports = plugin.sqlitePlugin;