是否可以这样做:
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');");
...
},
)
关于javascript - HTML 5 SQLite : Multiple Inserts in One Transaction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2120652/