I’m inserting hundreds of rows into a Local Database.
After this insert, I would like to SELECT * from that table to get and display all these records.
I tried putting the Select statement in the callback of the INSERT transaction, but it isn’t working properly. I tested the SELECT statement to see that it works, when I do a page refresh.
Can anyone help? After all the records are inserted, I want to be able to SELECT them all without refreshing the page. Thanks!
database.db.transaction(function (tx) {
JSON PROCESSING
tx.executeSql('INSERT INTO ...'),
[DATA IS HERE],
function (tx, callback) {
alert(callback.message);
database.db.transaction(function (tx) {
tx.executeSql('SELECT * from table;', [], tableSelectHandler, errorHandler);
});
},
function (tx, error) {
alert(error.message);
}
});
It’s a bit late to answer this particular question, but could help somebody, so…
The db.transaction function also has callback functions for Error and Success. You can place your SELECT code in the Success callback, and it will be executed at the end of the transaction, after all the Inserts are executed. Basically you should have something like this:
Hope it helps. Cheers!