Reputation: 28178
I'm currently playing around with the asynchronous API of WebSql. Given this code:
db.transaction(
function (tx) {
tx.executeSql("SELECT * FROM table",
[],
function(t, resultSet){ //Anonimous function implementing SQLStatementCallback
t.executeSql(...); //#1
}
);
},
function (err) {
console.error("Error in transaction");
},
function(){
console.log("Transaction complete"); //#2
}
);
I could not find this in the spec. The third parameter in executeSql
is a function inplementing SQLStatementCallback
. The first parameter in this interface is another SQLTransaction
(named t in my code). Would it be possible to use this transaction object to continue executing sentences? In particular:
t
the same as tx
?t
to execute another SQL sentence, and in this case is #1 guaranteed to run before #2?Upvotes: 0
Views: 180
Reputation: 13141
Yes, transaction object is same in t
and tx
.
Yes, It is grantee to run 1# before 2# since you have already listen onsuccess handler callback. I want to achieve ordering of the requests, i use t
. Whenever I want to let then run in parallel I use tx
. See the code in my websql request executor implementation YDN-DB library.
Upvotes: 1
Reputation: 180162
Yes, this is how the WebSQL API works.
Because of the asynchronous execution, this is the only way to execute multiple commands in one transaction.
Upvotes: 0