Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sqlite Cordova SQL-如何在单个事务中执行多个参数化insert语句_Sqlite_Cordova - Fatal编程技术网

Sqlite Cordova SQL-如何在单个事务中执行多个参数化insert语句

Sqlite Cordova SQL-如何在单个事务中执行多个参数化insert语句,sqlite,cordova,Sqlite,Cordova,我需要使用Cordova在SQLite数据库中执行多个insert语句。目前,我可以通过构造一个insert语句数组,然后在sql事务块中执行它们来实现这一点: function populateDB(tx) { if(sqls.length > 0) { for (var index = 0; index < sqls.length; index++) { tx.executeSql(sqls[index]); }

我需要使用Cordova在SQLite数据库中执行多个insert语句。目前,我可以通过构造一个insert语句数组,然后在sql事务块中执行它们来实现这一点:

function populateDB(tx) {

    if(sqls.length > 0) {
        for (var index = 0; index < sqls.length; index++) {
            tx.executeSql(sqls[index]);
        }
    }
}

function errorCB(err) {
    alert(err.message);
}

function successCB() {
    alert("insert success!");
}

db.transaction(populateDB, errorCB, successCB);
函数填充b(tx){
如果(sqls.length>0){
对于(var index=0;index
我了解到我可以将参数化语句与
tx.executeSql
函数一起使用,但如何将它们放入数组中,以便在单个事务中执行它们


谢谢

如果您有一个SQL语句数组,那么您需要将它修改得更复杂一些,以便它还包括绑定参数。我会换成一个简单对象数组。假设sqls是一个数组:

sqls[0]。sql将是sql语句:insert into(?,,?) sqls[0]。参数将是参数的数组:[2,“foo”,4]

您的代码将被修改为只使用每个部分