I'm attempting to pass a function an array that should run through a loop and call a db.transaction for each incremented SQL statement.
function updateColorData (colorArray) {
for (var i=0; i<colorArray.length; i++) {
var sql = 'INSERT INTO SPColorData (color) VALUES (\''+colorArray[i]+'\')';
if (i < colorArray.length-1) {
db.transaction(function (tx) {tx.executeSql(sql, [], gameOptionSuccess, errorCB)}, errorCB);
} else {
db.transaction(function (tx) {tx.executeSql(sql, [], colorDataQuery, errorCB)}, errorCB);
}
}
}
As a test I'm calling the updateColorData function passing in an array like this
['one', 'two', 'three', 'four']
but when I have the database read back the information it received I'm getting
['four', 'four', 'four', 'four']
I realize that calling 4 database transactions in a loop like this is not the most efficient method but I'm not sure why this isn't working or what other method to try.
Thanks!