I am currently trying to insert data from an array in to a WebSQL DB and am getting some weird results. I assume it is because of it being async.
The problem is i am trying to insert data using transactions inside a for loop that is also nested inside another transaction. The code almost works but is only completing the final transaction of the loop.
for (i = 0; i < array.gArr.length; i++)
{
var group_id = array.gArr[i].group_id;
var title = array.gArr[i].title;
var description = array.gArr[i].description;
var photo = array.gArr[i].default_photo;
tx_num = "tx" + i;
db.transaction(function (tx_num) {
tx_num.executeSql("INSERT OR IGNORE INTO my_groups(group_id, title, description, photo_url) VALUES (?,?,?,?)", [group_id, title, description, photo]);
});
}
The reason tx_num exists was an attempt to see if it was due to having the same tx name.
I have also tried using just INSERT INTO incase this was causing problems and the results are the same.
Just for your reference the table has been created using:
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS my_groups(group_id UNIQUE, title, description, photo_url)');
});
Any help would be appreciated.