@@ -83,11 +83,17 @@ argsArray = function(fun) {
83
83
84
84
plugin . exec = function ( method , options , success , error ) {
85
85
if ( plugin . sqlitePlugin . DEBUG ) {
86
- console . log ( 'SQLite.' + method + '(' + JSON . stringify ( options ) + ')' ) ;
86
+ plugin . log ( 'SQLite.' + method + '(' + JSON . stringify ( options ) + ')' ) ;
87
87
}
88
88
NativeModules [ "SQLite" ] [ method ] ( options , success , error ) ;
89
89
} ;
90
90
91
+ plugin . log = function ( ...messages ) {
92
+ if ( plugin . sqlitePlugin . DEBUG ) {
93
+ console . log ( ...messages )
94
+ }
95
+ }
96
+
91
97
SQLitePlugin = function ( openargs , openSuccess , openError ) {
92
98
var dbname ;
93
99
if ( ! ( openargs && openargs [ 'name' ] ) ) {
@@ -102,10 +108,10 @@ SQLitePlugin = function(openargs, openSuccess, openError) {
102
108
this . openSuccess = openSuccess ;
103
109
this . openError = openError ;
104
110
this . openSuccess || ( this . openSuccess = function ( ) {
105
- console . log ( "DB opened: " + dbname ) ;
111
+ plugin . log ( "DB opened: " + dbname ) ;
106
112
} ) ;
107
113
this . openError || ( this . openError = function ( e ) {
108
- console . log ( e . message ) ;
114
+ plugin . log ( e . message ) ;
109
115
} ) ;
110
116
this . open ( this . openSuccess , this . openError ) ;
111
117
} ;
@@ -128,9 +134,9 @@ SQLitePlugin.prototype.addTransaction = function(t) {
128
134
this . startNextTransaction ( ) ;
129
135
} else {
130
136
if ( this . dbname in this . openDBs ) {
131
- console . log ( 'new transaction is waiting for open operation' ) ;
137
+ plugin . log ( 'new transaction is waiting for open operation' ) ;
132
138
} else {
133
- console . log ( 'database is closed, new transaction is [stuck] waiting until db is opened again!' ) ;
139
+ plugin . log ( 'database is closed, new transaction is [stuck] waiting until db is opened again!' ) ;
134
140
}
135
141
}
136
142
} ;
@@ -158,12 +164,12 @@ SQLitePlugin.prototype.startNextTransaction = function() {
158
164
return function ( ) {
159
165
var txLock ;
160
166
if ( ! ( _this . dbname in _this . openDBs ) || _this . openDBs [ _this . dbname ] !== DB_STATE_OPEN ) {
161
- console . log ( 'cannot start next transaction: database not open' ) ;
167
+ plugin . log ( 'cannot start next transaction: database not open' ) ;
162
168
return ;
163
169
}
164
170
txLock = txLocks [ self . dbname ] ;
165
171
if ( ! txLock ) {
166
- console . log ( 'cannot start next transaction: database connection is lost' ) ;
172
+ plugin . log ( 'cannot start next transaction: database connection is lost' ) ;
167
173
} else if ( txLock . queue . length > 0 && ! txLock . inProgress ) {
168
174
txLock . inProgress = true ;
169
175
txLock . queue . shift ( ) . start ( ) ;
@@ -227,7 +233,7 @@ SQLitePlugin.prototype.sqlBatch = function(sqlStatements, success, error) {
227
233
if ( ! ! error ) {
228
234
return error ( e ) ;
229
235
} else {
230
- console . log ( "Error handler not provided: " , e ) ;
236
+ plugin . log ( "Error handler not provided: " , e ) ;
231
237
}
232
238
} ;
233
239
@@ -239,19 +245,19 @@ SQLitePlugin.prototype.open = function(success, error) {
239
245
var openerrorcb , opensuccesscb ;
240
246
241
247
if ( this . dbname in this . openDBs && this . openDBs [ this . dbname ] === DB_STATE_OPEN ) {
242
- console . log ( 'database already open: ' + this . dbname ) ;
248
+ plugin . log ( 'database already open: ' + this . dbname ) ;
243
249
nextTick ( ( function ( _this ) {
244
250
return function ( ) {
245
251
success ( _this ) ;
246
252
} ;
247
253
} ) ( this ) ) ;
248
254
} else {
249
- console . log ( 'OPEN database: ' + this . dbname ) ;
255
+ plugin . log ( 'OPEN database: ' + this . dbname ) ;
250
256
opensuccesscb = ( function ( _this ) {
251
257
return function ( ) {
252
258
var txLock ;
253
259
if ( ! _this . openDBs [ _this . dbname ] ) {
254
- console . log ( 'database was closed during open operation' ) ;
260
+ plugin . log ( 'database was closed during open operation' ) ;
255
261
}
256
262
if ( _this . dbname in _this . openDBs ) {
257
263
_this . openDBs [ _this . dbname ] = DB_STATE_OPEN ;
@@ -267,7 +273,7 @@ SQLitePlugin.prototype.open = function(success, error) {
267
273
} ) ( this ) ;
268
274
openerrorcb = ( function ( _this ) {
269
275
return function ( ) {
270
- console . log ( 'OPEN database: ' + _this . dbname + ' failed, aborting any pending transactions' ) ;
276
+ plugin . log ( 'OPEN database: ' + _this . dbname + ' failed, aborting any pending transactions' ) ;
271
277
if ( ! ! error ) {
272
278
error ( newSQLError ( 'Could not open database' ) ) ;
273
279
}
@@ -283,16 +289,16 @@ SQLitePlugin.prototype.open = function(success, error) {
283
289
SQLitePlugin . prototype . close = function ( success , error ) {
284
290
if ( this . dbname in this . openDBs ) {
285
291
if ( txLocks [ this . dbname ] && txLocks [ this . dbname ] . inProgress ) {
286
- console . log ( 'cannot close: transaction is in progress' ) ;
292
+ plugin . log ( 'cannot close: transaction is in progress' ) ;
287
293
error ( newSQLError ( 'database cannot be closed while a transaction is in progress' ) ) ;
288
294
return ;
289
295
}
290
- console . log ( 'CLOSE database: ' + this . dbname ) ;
296
+ plugin . log ( 'CLOSE database: ' + this . dbname ) ;
291
297
delete this . openDBs [ this . dbname ] ;
292
298
if ( txLocks [ this . dbname ] ) {
293
- console . log ( 'closing db with transaction queue length: ' + txLocks [ this . dbname ] . queue . length ) ;
299
+ plugin . log ( 'closing db with transaction queue length: ' + txLocks [ this . dbname ] . queue . length ) ;
294
300
} else {
295
- console . log ( 'closing db with no transaction lock state' ) ;
301
+ plugin . log ( 'closing db with no transaction lock state' ) ;
296
302
}
297
303
let mysuccess = function ( t , r ) {
298
304
if ( ! ! success ) {
@@ -303,13 +309,13 @@ SQLitePlugin.prototype.close = function(success, error) {
303
309
if ( ! ! error ) {
304
310
return error ( e ) ;
305
311
} else {
306
- console . log ( "Error handler not provided: " , e ) ;
312
+ plugin . log ( "Error handler not provided: " , e ) ;
307
313
}
308
314
} ;
309
315
plugin . exec ( "close" , { path : this . dbname } , mysuccess , myerror ) ;
310
316
} else {
311
317
var err = 'cannot close: database is not open' ;
312
- console . log ( err ) ;
318
+ plugin . log ( err ) ;
313
319
if ( error ) {
314
320
nextTick ( function ( ) {
315
321
return error ( err ) ;
@@ -321,11 +327,11 @@ SQLitePlugin.prototype.close = function(success, error) {
321
327
SQLitePlugin . prototype . attach = function ( dbNameToAttach , dbAlias , success , error ) {
322
328
if ( this . dbname in this . openDBs ) {
323
329
if ( txLocks [ this . dbname ] && txLocks [ this . dbname ] . inProgress ) {
324
- console . log ( 'cannot attach: transaction is in progress' ) ;
330
+ plugin . log ( 'cannot attach: transaction is in progress' ) ;
325
331
error ( newSQLError ( 'database cannot be attached while a transaction is in progress' ) ) ;
326
332
return ;
327
333
}
328
- console . log ( 'ATTACH database ' + dbNameToAttach + ' to ' + this . dbname + ' with alias ' + dbAlias ) ;
334
+ plugin . log ( 'ATTACH database ' + dbNameToAttach + ' to ' + this . dbname + ' with alias ' + dbAlias ) ;
329
335
330
336
let mysuccess = function ( t , r ) {
331
337
if ( ! ! success ) {
@@ -336,7 +342,7 @@ SQLitePlugin.prototype.attach = function(dbNameToAttach, dbAlias, success, error
336
342
if ( ! ! error ) {
337
343
return error ( e ) ;
338
344
} else {
339
- console . log ( "Error handler not provided: " , e ) ;
345
+ plugin . log ( "Error handler not provided: " , e ) ;
340
346
}
341
347
} ;
342
348
plugin . exec ( "attach" , { path : this . dbname , dbName : dbNameToAttach , dbAlias} , mysuccess , myerror ) ;
@@ -353,29 +359,29 @@ SQLitePlugin.prototype.attach = function(dbNameToAttach, dbAlias, success, error
353
359
SQLitePlugin . prototype . detach = function ( dbAlias , success , error ) {
354
360
if ( this . dbname in this . openDBs ) {
355
361
if ( txLocks [ this . dbname ] && txLocks [ this . dbname ] . inProgress ) {
356
- console . log ( 'cannot attach: transaction is in progress' ) ;
362
+ plugin . log ( 'cannot attach: transaction is in progress' ) ;
357
363
error ( newSQLError ( 'database cannot be attached while a transaction is in progress' ) ) ;
358
364
return ;
359
365
}
360
- console . log ( 'DETACH database ' + dbAlias + ' from ' + this . dbname ) ;
366
+ plugin . log ( 'DETACH database ' + dbAlias + ' from ' + this . dbname ) ;
361
367
362
368
let mysuccess = function ( t , r ) {
363
369
if ( ! ! success ) {
364
370
return success ( r ) ;
365
371
}
366
372
} ;
367
373
let myerror = function ( e ) {
368
- console . log ( 'ERR' , e ) ;
374
+ plugin . log ( 'ERR' , e ) ;
369
375
if ( ! ! error ) {
370
376
return error ( e ) ;
371
377
} else {
372
- console . log ( "Error handler not provided: " , e ) ;
378
+ plugin . log ( "Error handler not provided: " , e ) ;
373
379
}
374
380
} ;
375
381
this . executeSql ( 'DETACH DATABASE ' + dbAlias , [ ] , mysuccess , myerror )
376
382
} else {
377
383
var err = 'cannot attach: database is not open' ;
378
- console . log ( err ) ;
384
+ plugin . log ( err ) ;
379
385
if ( error ) {
380
386
nextTick ( function ( ) {
381
387
return error ( err ) ;
@@ -395,7 +401,7 @@ SQLitePlugin.prototype.executeSql = function(statement, params, success, error)
395
401
if ( ! ! error ) {
396
402
return error ( e ) ;
397
403
} else {
398
- console . log ( "Error handler not provided: " , e ) ;
404
+ plugin . log ( "Error handler not provided: " , e ) ;
399
405
}
400
406
} ;
401
407
myfn = function ( tx ) {
@@ -476,7 +482,7 @@ SQLitePluginTransaction.prototype.executeSql = function(sql, values, success, er
476
482
if ( ! ! error ) {
477
483
return error ( e ) ;
478
484
} else {
479
- console . log ( "Error handler not provided: " , e ) ;
485
+ plugin . log ( "Error handler not provided: " , e ) ;
480
486
}
481
487
} ;
482
488
that . addStatement ( sql , values , mysuccess , myerror ) ;
@@ -498,10 +504,10 @@ SQLitePluginTransaction.prototype.addStatement = function(sql, values, success,
498
504
}
499
505
else if ( t !== 'function' ) {
500
506
params . push ( v . toString ( ) ) ;
501
- console . warn ( 'addStatement - parameter of type <' + t + '> converted to string using toString()' )
507
+ plugin . warn ( 'addStatement - parameter of type <' + t + '> converted to string using toString()' )
502
508
} else {
503
509
let errorMsg = 'Unsupported parameter type <' + t + '> found in addStatement()' ;
504
- console . error ( errorMsg ) ;
510
+ plugin . error ( errorMsg ) ;
505
511
error ( newSQLError ( errorMsg ) ) ;
506
512
return ;
507
513
}
@@ -516,13 +522,13 @@ SQLitePluginTransaction.prototype.addStatement = function(sql, values, success,
516
522
} ;
517
523
518
524
SQLitePluginTransaction . prototype . handleStatementSuccess = function ( handler , response ) {
519
- // console .log('handler response:',response,response.rows);
525
+ // plugin .log('handler response:',response,response.rows);
520
526
var payload , rows ;
521
527
if ( ! handler ) {
522
528
return ;
523
529
}
524
530
rows = response . rows || [ ] ;
525
- // console .log('handler rows now:',rows);
531
+ // plugin .log('handler rows now:',rows);
526
532
payload = {
527
533
rows : {
528
534
item : function ( i ) {
@@ -540,7 +546,7 @@ SQLitePluginTransaction.prototype.handleStatementSuccess = function(handler, res
540
546
rowsAffected : response . rowsAffected || 0 ,
541
547
insertId : response . insertId || void 0
542
548
} ;
543
- // console .log('handler response payload:',payload);
549
+ // plugin .log('handler response payload:',payload);
544
550
handler ( this , payload ) ;
545
551
} ;
546
552
@@ -573,7 +579,7 @@ SQLitePluginTransaction.prototype.run = function() {
573
579
} catch ( err ) {
574
580
let errorMsg = JSON . stringify ( err ) ;
575
581
if ( errorMsg === "{}" ) errorMsg = err . toString ( ) ;
576
- console . log ( "warning - exception while invoking a callback: " + errorMsg ) ;
582
+ plugin . log ( "warning - exception while invoking a callback: " + errorMsg ) ;
577
583
}
578
584
579
585
if ( ! didSucceed ) {
@@ -629,7 +635,7 @@ SQLitePluginTransaction.prototype.run = function() {
629
635
} ;
630
636
631
637
var myerror = function ( error ) {
632
- console . log ( "batch execution error: " , error ) ;
638
+ plugin . log ( "batch execution error: " , error ) ;
633
639
} ;
634
640
635
641
plugin . exec ( "backgroundExecuteSqlBatch" , {
@@ -713,7 +719,7 @@ dblocations = {
713
719
SQLiteFactory = function ( ) { } ;
714
720
715
721
SQLiteFactory . prototype . DEBUG = function ( debug ) {
716
- console . log ( "Setting debug to:" , debug ) ;
722
+ plugin . log ( "Setting debug to:" , debug ) ;
717
723
plugin . sqlitePlugin . DEBUG = debug ;
718
724
} ;
719
725
@@ -821,7 +827,7 @@ SQLiteFactory.prototype.deleteDatabase = function(first,success, error) {
821
827
if ( ! ! error ) {
822
828
return error ( e ) ;
823
829
} else {
824
- console . log ( "deleteDatabase error handler not provided: " , e ) ;
830
+ plugin . log ( "deleteDatabase error handler not provided: " , e ) ;
825
831
}
826
832
} ;
827
833
@@ -831,7 +837,8 @@ SQLiteFactory.prototype.deleteDatabase = function(first,success, error) {
831
837
plugin . sqlitePlugin = {
832
838
SQLiteFactory : SQLiteFactory ,
833
839
SQLitePluginTransaction : SQLitePluginTransaction ,
834
- SQLitePlugin : SQLitePlugin
840
+ SQLitePlugin : SQLitePlugin ,
841
+ log : plugin . log
835
842
} ;
836
843
837
844
module . exports = plugin . sqlitePlugin ;
0 commit comments