Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I execute multiple statements in Web SQL?

Tags:

web-sql

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?

like image 530
digita1-anal0g Avatar asked Dec 04 '12 21:12

digita1-anal0g


People also ask

How do I run multiple SQL statements at once?

To run a query with multiple statements, ensure that each statement is separated by a semicolon; then set the DSQEC_RUN_MQ global variable to 1 and run the query. When the variable is set to zero, all statements after the first semicolon are ignored.

How do I fire multiple queries in SQL?

Simply put three queries one after the other in a . sql file, with semi-colons after each statement, then execute it as a script (either on a SQL*Plus prompt using @scriptname. sql or in TOAD/SQL Developer [or equivalent] using its script execution function).

Which of the following options is used to execute SQL query multiple times?

Statement interface can be used to execute static SQL queries whereas PreparedStatement interface is used to execute dynamic SQL queries multiple times.


1 Answers

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.

like image 170
Kyaw Tun Avatar answered Oct 20 '22 04:10

Kyaw Tun