I am trying to make a login system with WebSQL. The sign up works. However, I want to make a function to see if I can see the usernames in an array. This is my code (I have a column for name and password):
var db = openDatabase('personDB', '1.0', 'the data of people', 2*1024*1024);
var exists=[];
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM people', [], function (tx, results) {
var len = results.rows.length, i;
for (i = 0; i < len; i++) {
exists.push(results.rows.item(i).username);
}
});
});
return exists;
When I try it in a snap block, it doesn't report anything. Well, it reports something, but it reports a blank and empty array. However, when I try to do it in console, it works perfectly. Is there something I am doing wrong?
I'd appreciate it if I could get a quick response, because this is part of a project that is due tomorrow.
It works in the console. It returns an array with the data, but when I do it in snap, it just reports an empty array. Do you know if something is wrong?
Why are you using Web SQL? It's deprecated and has never been supported in Firefox.
The reason why it's not reporting is because you are using a callback. What you can do is report a function that resolves to a variable that contains the results (null initially) and wait until that variable is truthy.