I have a problem with a SQLite query on PhoneGap application. I would open a folder and make a select with where clause for every entries in the folder. I open a for loop, after a select query, but the script uses same variables for all the entries (it remembers only the last record's variables). The loop reads correctly the number of entries, but it works only with one record's variables, and it works for as many times as there are files in the folder only with these variables.
function readerSuccess(entries) {
var db = window.openDatabase("Test", "1.0", "Demo test", 200000);
db.transaction(function(tx) {
var i;
for (i=0; i<entries.length; i+=1) {
var imgName=entries[i].name;
var upfi=entries[i];
console.log(imgName);
tx.executeSql("SELECT * FROM FOTO WHERE img=?", [imgName], function(tx, result) {
console.log(imgName+" after SQL");
var dataset = result.rows;
console.log("Returned rows = " + dataset.length);
if (dataset.length==0) {
console.log('No rows!');
console.log('File sync: '+imgName);
} else {
console.log('File already sync: '+imgName);
};
}, successCB, errorCB)}}, successCB, errorCB);
};
I have tested with global variables or local variables without a success. I do not know where to turn!! :(