I'm developing a small Javascript application that makes use of Web SQL. I want to create a function that returns the value of a variable from the VARIABLES table, as well as its observation. It would be something like this:
valor = pegaVariavel("nome da variavel");
Unfortunately I can not do this. The code I'm using for this is:
function pegaVariavel(variavel, obs) {
var valores = { observacao: '', valor: ''};
html5sql.process([{
"sql" : "SELECT valor, obs FROM variaveis WHERE variavel=?",
"data" : [variavel],
"success": function() {}
}],
dbSuccess,
function(e) { console.log("Erro ao recuperar variavel do banco: "+ e.message) });
function dbSuccess(t, r) {
console.log("Valor da Variavel "+variavel+" resgatado do banco com sucesso.");
valores.observacao = r.rows.item(0)[['obs']];
valores.valor = r.rows.item(0)[['valor']];
}
if (obs == 1) {
console.log('Observação da variavel '+variavel+': '+r.rows.item(0)[['obs']]);
}
if (obs == 2) {
return valores.observacao;
}
if (typeof obs == 'undefined') {
return valores.valor;
}
}
I'm using the html5sql library to work with the bank , # "> HTML5SQL.JS
How can I resolve this?