4
I am developing a small Javascript application that makes use of Web SQL. I want to create a function that returns the value of a variable in the VARIABLES table, as well as its observation. It would look something like this:
valor = pegaVariavel("nome da variavel");
Unfortunately I’m not able to do that. 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;
}
}
Obs: I am using html5sql library to work with the database, HTML5SQL.JS
How can I fix this?