I am using WebSQL plugin https://github.com/MSOpenTech/cordova-plugin-websql for a windows phone 8.1 phonegap app. Below is the code.
var db = openDatabase(DATABASE_NAME, DATABASE_VERSION, function () {
//showMessage('db successfully opened or created',"Success");
});
function getPid() {
if(pid==0){
return getSetting("pid");
} else {
return 0;
}
}
function getSetting(key)
{
if(key.length == 0){
return 0;
}
db.transaction(function (tx1) {
tx1.executeSql("SELECT KEY_VAL FROM TABLE_SETTINGS WHERE KEY_NAME='"+key+"' LIMIT 1",[],function(t,data){
if (data.rows.length > 0) {
return data.rows[0].KEY_VAL;
}
}, onError);
});
return 0;
}
Since tx1.executeSql() is a asynchronous function, I get two pid values as 0 and then the correct value. How can I get the correct value from the 1st time only as I need to use this value in another query?