2

I am trying to get the whole result as array of rows from sqlite query results object:

I have tried results.rows.item(i).id and it work just fine but I need to get the whole array of rows instead of only one item, i tried to use rows.array (_number) from Expo documentation but I can't figure out how actually to use .array(_number)

my code snippet:

iris.transaction(tx => {
    tx.executeSql(
        `select id, date from days`,
        [],
        (tx, results) => {
            for(i=0; i<results.rows.length; i++){
                var date = results.rows.item(i).date.split('-');
            }
        }
    )
});

1 Answer 1

3

As per the Expo document, the result.rows has an _array which returns all the items as array, you can try like

if (result && result.rows && result.rows._array) {
  /* do something with the items */
  // result.rows._array holds all the results.
}

Hope this will help!

Sign up to request clarification or add additional context in comments.

2 Comments

As an added note for TypeScript users, it seems that TypeScript really doesn't like SQLResultSetRowList - when I try to use rows._array, I get an array saying the property _array does not exist on type rows. So, if you run into this, just reassign the rows object to a new variable and cast it to type any - you'll lose the validation, but you won't have the annoying error anymore!
@ArmandoVasquez thanks, it works. You should really consider writing this in an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.