HTML 5 SQLite:一个事务中的多个插入。

时间:2022-11-26 10:09:18

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?

…在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 个解决方案

#1


7  

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

下面是示例代码。我在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');");
    ...
},

)

)

#1


7  

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

下面是示例代码。我在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');");
    ...
},

)

)