Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the cause of a sql error from Expo SQLite API?

Having the following code:

import { SQLite } from 'expo';

const db = SQLite.openDatabase('mydb.db')
db.transaction( tx => {
  tx.executeSql('insert into invalidTable values (?,?)', [1,2], null, (transact, err) => {
    //I can't find error description in the objects below
    console.log({transact, err})
  })
})

How can I get the sqlite error message, to determine what exactly was the cause of this error (in this case, an invalid table)?

The API documentation says my error function "Takes two parameters: the transaction itself, and the error object", but I couldn't find the error description in none of these.

I did a snack simulating this scenario.

like image 737
Edumelzer Avatar asked Mar 08 '18 16:03

Edumelzer


1 Answers

This logs the errors for me

  import { SQLite } from 'expo';

  const db = SQLite.openDatabase('mydb.db')

  db.transaction(tx => {
    tx.executeSql(sql, params, (_, { rows }) => {
      console.log(rows._array)
    }, (t, error) => {
      console.log(error);
    })
  })
like image 163
Anders B Avatar answered Oct 04 '22 02:10

Anders B