0

我正在尝试使用 react-native-sqlite-storage 插件执行一个Sqlite简单React-Native查询。根据文档,我应该将两个参数放入成功回调 1)SQLite.Transaction和 2)SQLlite.ResultSet 但我只SQLite.Transaction在我的示例中得到了。

let sql = "SELECT * FROM table_a;"
let params = [];

db.executeSql(sql, params,
  (trans, results) => {
    console.log("execute success results: " + JSON.stringify(results))
    console.log("execute success transaction: " + JSON.stringify(trans))
    //resolve(results);
    resolve(trans);
  },
  (error) => {
    console.log("execute error: " + error);
    reject(error);
});  

控制台输出

execute success results: undefined
execute success transaction: {"rows":{"length":1},"rowsAffected":0}  
4

1 回答 1

0

我忘了把我的包裹executeSql在一个transaction. 这按预期工作:

db.transaction((txn) => {
    txn.executeSql(sql, params, (trans, results) => {
        console.log("execute success results: " + JSON.stringify(results))
        console.log("execute success transaction: " + JSON.stringify(trans))
        //resolve(results);
        resolve(trans);
    },
        (error) => {
        console.log("execute error: " + JSON.stringify(error))
        reject(error);
    });
});
于 2021-10-12T18:33:39.953 回答