@@ -651,6 +651,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
651
651
*
652
652
* This is a wrapper against
653
653
* {@link Database.prepare},
654
+ * {@link Statement.bind},
654
655
* {@link Statement.step},
655
656
* {@link Statement.get},
656
657
* and {@link Statement.free}.
@@ -660,7 +661,8 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
660
661
* by a semicolon)
661
662
*
662
663
* ## Example use
663
- * We have the following table, named *test* :
664
+ * We will create following table, named *test* and query it with a
665
+ * multi-line statement using params:
664
666
*
665
667
* | id | age | name |
666
668
* |:--:|:---:|:------:|
@@ -671,18 +673,44 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
671
673
* We query it like that:
672
674
* ```javascript
673
675
* var db = new SQL.Database();
674
- * var res = db.exec("SELECT id FROM test; SELECT age,name FROM test;");
676
+ * var res = db.exec(
677
+ * (
678
+ * "DROP TABLE IF EXISTS test;\n"
679
+ * + "CREATE TABLE test (id INTEGER, age INTEGER, name TEXT);\n"
680
+ * + "INSERT INTO test VALUES ($id1, :age1, @name1);\n"
681
+ * + "INSERT INTO test VALUES ($id2, :age2, @name2);\n"
682
+ * + "INSERT INTO test VALUES ($id3, :age3, @name3);\n"
683
+ * + "SELECT id FROM test;\n"
684
+ * + "SELECT age,name FROM test;\n"
685
+ * ),
686
+ * {
687
+ * "$id1": 1,
688
+ * ":age1": 1,
689
+ * "@name 1": "Ling",
690
+ * "$id2": 2,
691
+ * ":age2": 18,
692
+ * "@name2": "Paul",
693
+ * "$id3": 3,
694
+ * ":age3": 3,
695
+ * "@name3": "Marcus"
696
+ * }
697
+ * );
675
698
* ```
676
699
*
677
700
* `res` is now :
678
701
* ```javascript
679
702
* [
680
- * {columns: ['id'], values:[[1],[2],[3]]},
681
- * {columns: [' age',' name'], values:[[1,' Ling' ],[18,' Paul' ],[3,'Markus' ]]}
703
+ * {" columns":["id"]," values" :[[1],[2],[3]]},
704
+ * {" columns":[" age"," name"]," values" :[[1," Ling" ],[18," Paul" ],[3,"Marcus" ]]}
682
705
* ]
683
706
* ```
684
707
*
685
- * @param {string } sql a string containing some SQL text to execute
708
+ @param {string } sql a string containing some SQL text to execute
709
+ @param {any[] } [params=[]] When the SQL statement contains placeholders,
710
+ you can pass them in here. They will be bound to the statement
711
+ before it is executed. If you use the params argument as an array,
712
+ you **cannot** provide an sql string that contains several queries
713
+ (separated by `;`). This limitation does not apply to params as an object.
686
714
* @return {Database.QueryExecResult[] } The results of each statement
687
715
*/
688
716
Database . prototype [ "exec" ] = function exec ( sql , params ) {
0 commit comments