HTML 5 SQLite: Multiple Inserts in One Transaction

懵懂的女人 提交于 2020-01-15 03:10:09

问题


Is it possible to do something like this:

begin;
    insert into some_table (some_col, another_col) values ('a', 'b');
    insert into some_table (some_col, another_col) values ('c', 'd');
    ...
commit;

...in HTML 5?

With each transaction being async and having it's own callback, seems to me that it would be difficult to write a routine that inserts an unknown amount of rows, and then calls back when it has completed.


回答1:


Here is sample code of how you do it. I tested in on recent versions of safari and chrome in macos, ios and android.

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');");
    ...
},

)



来源:https://stackoverflow.com/questions/2120652/html-5-sqlite-multiple-inserts-in-one-transaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!