-1
I am using a Websql database to save usage license information in a Phonegap application. At any time of the system I will need to access this information, so I intend to save this into a global variable in the form of an array. This license of use, when opening the program I run a function to search the information in the Websql of the same, but I am not able to insert the return of the function within this global variable. Here comes the code:
<!-- language: lang-js -->
//license
LIC = [];
//WebSQL Connect
conn = openDatabase('test', 'test', 'test', 200 * 1024 * 1024);
//return license
function(){
conn.transaction(function (tx) {
//sql
tx.executeSql('SELECT * FROM license', [], function (tx, results) {
var len = results.rows.length, i;
//create array response
for (i = 0; i < len; i++){
//insert values on response
LIC['cpfCnpj'] = results.rows.item(i).cpfCnpj;
LIC['serial'] = results.rows.item(i).serial;
LIC['apiHash'] = results.rows.item(i).apiHash;
LIC['status'] = results.rows.item(i).status;
};
console.log(LIC); //aqui LIC retorna
}, null);
console.log(LIC); //aqui não retorna
});
}
console.log(LIC); //aqui não retorna
someone has a light there to help me?
does the following, in
console.log(LIC);
put to show with an identifier to differentiate one from the other, likeconsole.log("1º - " + LIC);
, and puts the order in which he returned theconsole.log
and put here, because very likelyconsole.log(LIC);
of Callback be the last to be executed for being asynchronous, so the others who will run regardless of Callback’s response and will not have anything at all– Enzo Tiezzi