0
I’m making an appointment with Sqlite Bank. But the function ends up giving return before the consultation is performed. I am trying to solve this using a type of control while the query does not proceed. Is there any way to resolve this issue?
My code is below:
model.executarSql = function (sSql) {
var bExec = false; // Controle se pode prosseguir ou não
db.transaction(function(tx){
tx.executeSql(sSql, [], function(txs, results){
var aRet = []; // Array bidimensional com todos os resultados
var aItem = []; // Array com um resultado por vez
for(it = 0; it < results.rows.length; it++){
while (aItem.length > 0){ aItem.pop() }; // limpar o array
for(cp = 0; cp < results.rows.item(it).length; cp++){
aItem.push(results.rows.item(it)[cp]);
}
aRet.push(aItem);
}
bExec = true;
});
});
while (!bExec){
// Aguardar a consulta ao banco
};
return aRet;
};
Rodrigo, Javascript works asynchronously. I suggest you take a look at
callback
andPromise
. I had the same problem in understanding await Callback– Developer