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?
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.
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).
Statement interface can be used to execute static SQL queries whereas PreparedStatement interface is used to execute dynamic SQL queries multiple times.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With