[Solved] Request SQLite return "undefined" only for one column

Hello,

I have a strange problem (or maybe a stupid simple one).
I make a request in a table (SQLite database) that returns me correctly all the data, except for one column.
I deleted it, recreated it, changed its type, deleted the other columns. Every time it turns me off it’s “undefined”. The column should normally return 0 or 1. So I have no idea what the problem is.

My code :

    public getAll() {
    return new Promise((resolve, reject) => {
        this.storage.executeSql("SELECT * FROM places", []).then((data) => {
            let places = [];
            if(data.rows.length > 0) {
                for(let i = 0; i < data.rows.length; i++) {
                    places.push({
                        id: data.rows.item(i).id,
                        name: data.rows.item(i).name,
                        top: data.rows.item(i).top
                    });
                }
                console.table(places);
            }
            resolve(places);
        }, (error) => {
            reject(error);
        });
    });
} 

Thank you very much for help :slight_smile:

1 Like

You’ve got three columns here…which one is undefined? You could also simplify this code a bit

public getAll() {
  return this.storage.executeSql("SELECT * FROM places", [])
    .then(data => {
      const places = [];
      for(let i = 0; i < data.rows.length; i++) {
        places.push(data.rows.item(i));
      }
      console.table(places);
      return places;
    });
}

This does exactly the same thing as your code (unless you are filtering out columns in your loop. You’re wrapping things in promises a bunch for no reason, and catching your error only to directly re-reject it.

Thanks for your help and the simplify version.
The column is “top”.
And I just realized that it seems to keep an old database version. I made a change on a field but this change is not reflected in the app.

Problem solved. I don’t know why, but I just changed the name of the database and the data is displayed correctly.