How do I execute multiple statements in Web SQL?
Asked Answered
N

1

10

Is there a way to execute multiple statements in a single transaction? I want to do something like:

db.transaction(function (tx) {
    tx.executeSql(
        "CREATE TABLE Foo(ID INTEGER); CREATE TABLE Bar(ID INTEGER)",
        function (tx, result) {
            alert("success!");
        });
    });

But instead, I'm finding I have to do something like this instead:

db.transaction(function (tx) {
    tx.executeSql("CREATE TABLE Foo(ID INTEGER)");
    tx.executeSql("CREATE TABLE Bar(ID INTEGER)",
        function (tx, result) {
            alert("success!");
        });
    });

Am I limited to having to execute individual statements in their own transaction and then fire off a successFn on the last transaction or is there a way I can execute multiple statements in a single transaction?

Newsom answered 4/12, 2012 at 21:52 Comment(0)
O
7

Your second code is already executing multiple statements in a single transaction. The first code is not correct (not supported) since it is not clear which result to return the callback.

Even if supported, the performance is the same since internally, it will have to converted into second statement.

Oceania answered 4/12, 2012 at 23:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.