Iterating over an array of SQL data


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++) {
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.

return new List( exists);

Sorry, I tried it but the list has no elements. I think the problem lies in the for loop's body, because it does not work however I do it.

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?

Async closure!!!

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.


You didn't explain why that was the problem.

It's fine, I realized that WebSQL was deprecated, so I just used LocalStorage. I know, not the best solution, but best I have right now.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.