1
- /*jslint browser*/
1
+ /*jslint browser this */
2
2
/*global Module stackAlloc*/
3
3
4
4
@@ -195,7 +195,9 @@ This function binds these parameters to the given values.
195
195
196
196
## Binding values to named parameters
197
197
@example Bind values to named parameters
198
- var stmt = db.prepare("UPDATE test SET a=@newval WHERE id BETWEEN $mini AND $maxi");
198
+ var stmt = db.prepare(
199
+ "UPDATE test SET a=@newval WHERE id BETWEEN $mini AND $maxi"
200
+ );
199
201
stmt.bind({$mini:10, $maxi:20, '@newval ':5});
200
202
- Create a statement that contains parameters like '$VVV', ':VVV', '@VVV'
201
203
- Call Statement.bind with an object as parameter
@@ -293,7 +295,8 @@ Statement.prototype.getBlob = function(pos) {
293
295
294
296
/* Get one row of results of a statement.
295
297
If the first parameter is not provided, step must have been called before get.
296
- @param [Array,Object] Optional: If set, the values will be bound to the statement, and it will be executed
298
+ @param [Array,Object] Optional: If set, the values will be bound
299
+ to the statement, and it will be executed
297
300
@return [Array<String,Number,Uint8Array,null>] One row of result
298
301
299
302
@example Print all the rows of the table test to the console
@@ -339,7 +342,8 @@ Statement.prototype["get"] = function(params) {
339
342
var x'616200' AS data;
340
343
var NULL AS null_value;");
341
344
stmt.step(); // Execute the statement
342
- console.log(stmt.getColumnNames()); // Will print ['nbr','data','null_value']
345
+ console.log(stmt.getColumnNames());
346
+ // Will print ['nbr','data','null_value']
343
347
*/
344
348
Statement . prototype [ "getColumnNames" ] = function ( ) {
345
349
var i ;
@@ -357,7 +361,8 @@ Statement.prototype["getColumnNames"] = function() {
357
361
358
362
/* Get one row of result as a javascript object, associating column names with
359
363
their value in the current row.
360
- @param [Array,Object] Optional: If set, the values will be bound to the statement, and it will be executed
364
+ @param [Array,Object] Optional: If set, the values will be bound
365
+ to the statement, and it will be executed
361
366
@return [Object] The row of result
362
367
@see [Statement.get](#get-dynamic)
363
368
@@ -367,7 +372,8 @@ their value in the current row.
367
372
var x'616200' AS data;
368
373
var NULL AS null_value;");
369
374
stmt.step(); // Execute the statement
370
- console.log(stmt.getAsObject()); // Will print {nbr:5, data: Uint8Array([1,2,3]), null_value:null}
375
+ console.log(stmt.getAsObject());
376
+ // Will print {nbr:5, data: Uint8Array([1,2,3]), null_value:null}
371
377
*/
372
378
Statement . prototype [ "getAsObject" ] = function ( params ) {
373
379
var i ;
@@ -390,7 +396,8 @@ Statement.prototype["getAsObject"] = function(params) {
390
396
} ;
391
397
392
398
/* Shorthand for bind + step + reset
393
- Bind the values, execute the statement, ignoring the rows it returns, and resets it
399
+ Bind the values, execute the statement, ignoring the rows it returns,
400
+ and resets it
394
401
@param [Array,Object] Value to bind to the statement
395
402
*/
396
403
Statement . prototype [ "run" ] = function ( values ) {
@@ -456,7 +463,10 @@ Statement.prototype.bindValue = function(val, pos) {
456
463
} else if ( val . length != null ) {
457
464
return this . bindBlob ( val , pos ) ;
458
465
} else {
459
- throw "Wrong API use : tried to bind a value of an unknown type (" + val + ")." ;
466
+ throw (
467
+ "Wrong API use : tried to bind a value of an unknown type ("
468
+ + val + ")."
469
+ ) ;
460
470
}
461
471
}
462
472
} ;
@@ -496,11 +506,15 @@ Statement.prototype.bindFromArray = function(values) {
496
506
} ;
497
507
498
508
/* Reset a statement, so that it's parameters can be bound to new values
499
- It also clears all previous bindings, freeing the memory used by bound parameters.
509
+ It also clears all previous bindings, freeing the memory used
510
+ by bound parameters.
500
511
*/
501
512
Statement . prototype [ "reset" ] = function ( ) {
502
513
this . freemem ( ) ;
503
- return sqlite3_clear_bindings ( this . stmt ) === SQLITE_OK && sqlite3_reset ( this . stmt ) === SQLITE_OK ;
514
+ return (
515
+ sqlite3_clear_bindings ( this . stmt ) === SQLITE_OK
516
+ && sqlite3_reset ( this . stmt ) === SQLITE_OK
517
+ ) ;
504
518
} ;
505
519
506
520
/* Free the memory allocated during parameter binding
@@ -540,13 +554,17 @@ Database = function (data) {
540
554
/* Execute an SQL query, ignoring the rows it returns.
541
555
542
556
@param sql [String] a string containing some SQL text to execute
543
- @param params [Array] (*optional*) When the SQL statement contains placeholders, you can pass them in here. They will be bound to the statement before it is executed.
557
+ @param params [Array] (*optional*) When the SQL statement contains placeholders,
558
+ you can pass them in here. They will be bound to the statement
559
+ before it is executed.
544
560
545
- If you use the params argument, you **cannot** provide an sql string that contains several
546
- queries (separated by ';')
561
+ If you use the params argument, you **cannot** provide an sql string
562
+ that contains several queries (separated by ';')
547
563
548
564
@example Insert values in a table
549
- db.run("INSERT INTO test VALUES (:age, :name)", {':age':18, ':name':'John'});
565
+ db.run(
566
+ "INSERT INTO test VALUES (:age, :name)", {':age':18, ':name':'John'}
567
+ );
550
568
551
569
@return [Database] The database object (useful for method chaining)
552
570
*/
@@ -574,7 +592,8 @@ This is a wrapper against Database.prepare, Statement.step, Statement.get,
574
592
and Statement.free.
575
593
576
594
The result is an array of result elements. There are as many result elements
577
- as the number of statements in your sql string (statements are separated by a semicolon)
595
+ as the number of statements in your sql string (statements are separated
596
+ by a semicolon)
578
597
579
598
Each result element is an object with two properties:
580
599
'columns' : the name of the columns of the result (as returned by Statement.getColumnNames())
@@ -625,7 +644,13 @@ Database.prototype["exec"] = function(sql) {
625
644
while ( getValue ( nextSqlPtr , "i8" ) !== NULL ) {
626
645
setValue ( apiTemp , 0 , "i32" ) ;
627
646
setValue ( pzTail , 0 , "i32" ) ;
628
- this . handleError ( sqlite3_prepare_v2_sqlptr ( this . db , nextSqlPtr , - 1 , apiTemp , pzTail ) ) ;
647
+ this . handleError ( sqlite3_prepare_v2_sqlptr (
648
+ this . db ,
649
+ nextSqlPtr ,
650
+ - 1 ,
651
+ apiTemp ,
652
+ pzTail
653
+ ) ) ;
629
654
pStmt = getValue ( apiTemp , "i32" ) ;
630
655
nextSqlPtr = getValue ( pzTail , "i32" ) ;
631
656
if ( pStmt === NULL ) {
@@ -656,15 +681,17 @@ Database.prototype["exec"] = function(sql) {
656
681
657
682
/* Execute an sql statement, and call a callback for each row of result.
658
683
659
- **Currently** this method is synchronous, it will not return until the callback has
660
- been called on every row of the result. But this might change.
684
+ **Currently** this method is synchronous, it will not return until the callback
685
+ has been called on every row of the result. But this might change.
661
686
662
- @param sql [String] A string of SQL text. Can contain placeholders that will be
663
- bound to the parameters given as the second argument
664
- @param params [Array<String,Number,null,Uint8Array>] (*optional*) Parameters to bind
665
- to the query
666
- @param callback [Function(Object)] A function that will be called on each row of result
667
- @param done [Function] A function that will be called when all rows have been retrieved
687
+ @param sql [String] A string of SQL text. Can contain placeholders
688
+ that will be bound to the parameters given as the second argument
689
+ @param params [Array<String,Number,null,Uint8Array>] (*optional*) Parameters
690
+ to bind to the query
691
+ @param callback [Function(Object)] A function that will be called on each row
692
+ of result
693
+ @param done [Function] A function that will be called when all rows
694
+ have been retrieved
668
695
669
696
@return [Database] The database object. Useful for method chaining
670
697
@@ -695,7 +722,8 @@ Database.prototype["each"] = function(sql, params, callback, done) {
695
722
} ;
696
723
697
724
/* Prepare an SQL statement
698
- @param sql [String] a string of SQL, that can contain placeholders ('?', ':VVV', ':AAA', '@AAA')
725
+ @param sql [String] a string of SQL, that can contain placeholders
726
+ ('?', ':VVV', ':AAA', '@AAA')
699
727
@param params [Array] (*optional*) values to bind to placeholders
700
728
@return [Statement] the resulting statement
701
729
@throw [String] SQLite error
@@ -872,7 +900,10 @@ Database.prototype["create_function"] = function(name, func) {
872
900
sqlite3_result_blob ( cx , blobptr , result . length , - 1 ) ;
873
901
_free ( blobptr ) ;
874
902
} else {
875
- sqlite3_result_error ( cx , "Wrong API use : tried to return a value of an unknown type (" + result + ")." , - 1 ) ;
903
+ sqlite3_result_error ( cx , (
904
+ "Wrong API use : tried to return a value "
905
+ + "of an unknown type (" + result + ")."
906
+ ) , - 1 ) ;
876
907
}
877
908
break ;
878
909
default :
@@ -885,7 +916,17 @@ Database.prototype["create_function"] = function(name, func) {
885
916
}
886
917
func_ptr = addFunction ( wrapped_func ) ;
887
918
this . functions [ name ] = func_ptr ;
888
- this . handleError ( sqlite3_create_function_v2 ( this . db , name , func . length , SQLITE_UTF8 , 0 , func_ptr , 0 , 0 , 0 ) ) ;
919
+ this . handleError ( sqlite3_create_function_v2 (
920
+ this . db ,
921
+ name ,
922
+ func . length ,
923
+ SQLITE_UTF8 ,
924
+ 0 ,
925
+ func_ptr ,
926
+ 0 ,
927
+ 0 ,
928
+ 0
929
+ ) ) ;
889
930
return this ;
890
931
} ;
891
932
0 commit comments