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
Javascript HTML5SQLite:一个事务中的多个插入_Javascript_Sqlite_Html - Fatal编程技术网

Javascript HTML5SQLite:一个事务中的多个插入

Javascript HTML5SQLite:一个事务中的多个插入,javascript,sqlite,html,Javascript,Sqlite,Html,是否可以这样做: begin; insert into some_table (some_col, another_col) values ('a', 'b'); insert into some_table (some_col, another_col) values ('c', 'd'); ... commit; …在HTML 5中 由于每个事务都是异步的,并且有自己的回调,在我看来,编写一个例程插入未知数量的行,然后在完成后回调是很困难的。下面是如何执行的示例代码

是否可以这样做:

begin;
    insert into some_table (some_col, another_col) values ('a', 'b');
    insert into some_table (some_col, another_col) values ('c', 'd');
    ...
commit;
…在HTML 5中


由于每个事务都是异步的,并且有自己的回调,在我看来,编写一个例程插入未知数量的行,然后在完成后回调是很困难的。

下面是如何执行的示例代码。我在macos、ios和android上测试了safari和chrome的最新版本

var db = openDatabase('dbname', '1.0', 'db description', 1024 * 1024);
db.transaction(function (tx) {
    tx.executeSql("insert into some_table (some_col, another_col) values ('a', 'b');");
    tx.executeSql("insert into some_table (some_col, another_col) values ('c', 'd');");
    ...
},

)

简短的回答是肯定的。显然,在事务内部,executeSql命令是排队的。您可以循环并执行事务中的所有execute语句。只有在所有executeSql语句运行后,事务回调才会触发。