I need your help to create a SQLite class which allows send a query and returns the result.
I know transaction / executesql are asynchronous and I am trying to resolve this problem.
I wrote this code:
function SQLite(pName){
this.result = null;
//External function
this.Query = function(pQueryStr) {
this.result = null;
execQuery(pQueryStr);
//Waiting query result. While is null, sleep...
while(this.result == null){null;} //This line doesn't work
return this.result;
}
//Internal function for execute query
function execQuery(pQueryStr) {
//Emulating transacion-executesql functions with lag
setTimeout(function(){
this.result = "my query result";
}, 3000);
}
}
db = new SQLite("dbName");
var res = db.Query("query request string");
//As I can't wait for SQL result, 'res' returns null.
alert("External result: " + res);
This doesn't work but commenting 'while' line... this works adding this code to end.
setTimeout(function(){
alert("External result (with lag): " + this.result);
}, 5000);
My problem: I need 'while'. This make function waits for query result is reported.
Any solution or workaround?
Thanks for your time!