HTML 5 SQLite:一次交易中多次插入 [英] HTML 5 SQLite: Multiple Inserts in One Transaction

查看:41
本文介绍了HTML 5 SQLite:一次交易中多次插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以执行以下操作:

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;

...在HTML 5中?

...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.

推荐答案

以下是有关操作方法的示例代码.我在macos,ios和android中对Safari和chrome的最新版本进行了测试.

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

)

这篇关于HTML 5 SQLite:一次交易中多次插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆