Pretty sure the answer to this question is "closures" but I'm having a hard time getting it right. Given the following:
var total = 0;
db.readTransaction(function (tx) {
tx.executeSql('SELECT COUNT(id) AS mytotal FROM sometable', [], function (tx, results) {
total =results.rows.item(0).mytotal;
console.log(total);
});
});
console.log(total);
The first log statement will log the correct count but the second will log 0. Pretty sure a closure is the answer but ... how?