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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.