jarcoal
jarcoal

Reputation: 1445

HTML 5 SQLite: Multiple Inserts in One Transaction

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.

Upvotes: 2

Views: 10079

Answers (1)

gae123
gae123

Reputation: 9467

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

)

Upvotes: 7

Related Questions