【问题标题】:How can I get the cause of a sql error from Expo SQLite API?如何从 Expo SQLite API 获取 sql 错误的原因?
【发布时间】:2018-03-08 16:42:16
【问题描述】:

有以下代码:

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})
  })
})

如何获取 sqlite 错误消息,以确定此错误的确切原因(在本例中为无效表)?

API documentation 说我的错误函数“采用两个参数:事务本身和错误对象”,但我在这些中都找不到错误描述。

我做了一个snack 模拟这个场景。

【问题讨论】:

    标签: react-native expo create-react-native-app


    【解决方案1】:

    这会为我记录错误

      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);
        })
      })
    

    【讨论】:

      猜你喜欢
      • 2019-04-16
      • 2012-01-21
      • 2019-08-29
      • 2019-11-26
      • 1970-01-01
      • 2022-06-10
      • 1970-01-01
      • 2023-03-22
      • 2021-08-09
      相关资源
      最近更新 更多