Reputation: 4493
I want to run a transaction inside a for loop. My code is :-
for(var i=0;i<len;i++){
// some code
alert('before transaction');
var db = window.openDatabase("Database", "1.0", "Pin Point", 200000);
db.transaction(fetchSubList, errorLists);
alert('after transaction');
}
function fetchSubList(tx) {
tx.executeSql('some QUERY', [], fetchSubListSuccess, errorLists);
}
function fetchSubListSuccess(tx, results) {
alert("fetchSubListSuccess()...");
// some code
}
But the problem is that after the alert (before transaction) i directly get alert (after transaction) and only when the for loop ends then the transaction start....
I followed the this link to solve but still i'm not able to figure it out....
Upvotes: 0
Views: 2110
Reputation: 4493
It is not possible to do it... We need to refactor the code so that code looks like this :-
db.transaction(function(tx)
{
// some value
var loop_limit = 10
for(var i=0; i<loop_limit;i++ ){ // ITERATE HERE
tx.executeSql(Statement, [],Sucess, error);
}
});
Upvotes: 1