SQlite query response

I posted this on SO but it seems like there’s not much traction for Expo. So posting here:
According to Expo documentation with SQLite I would make a query like so:

`tx.executeSql(sqlStatement, arguments, success, error)`

I execute it like this:

db.transaction(tx => {
  tx.executeSql('SELECT * FROM dr_report_properties WHERE orderId = (?)', [this.state.orderId]);
},
  error => {
    alert(error);
  },
  (tx, results) => {
    console.log(results);
  }
);

My question is how do I get the response? The above returns as undefined. I then try (not expecting it to work but just for kicks)

console.log(tx);

This does give a console.log

(tx, results) => {
        console.log('I got data');
      }
    )

According to the documentation:

ResultSet objects are returned through second parameter of the success callback for the tx.executeSql() method on a Transaction (see above). They have the following form:
{
  insertId,
  rowsAffected,
  rows: {
    length,
    item(),
    _array,
  },
}

I would expect result would be this object. Any ideas at what I’m doing wrong?

Hey @impactcolor!

Took me a little bit to figure it out, but the success and error callbacks are part of the executeSql method, so it should be written like this (for example)

db.transaction(
      tx => {
        tx.executeSql('select * from my_table', [], (trans, result) => {
          console.log(trans, result)
        });
      }
    );

I tested in this snack and it works!

This did it @charliecruzan, thank you!

1 Like

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