Home > Enterprise >  Sqlite executeSql is not returning ResultSet
Sqlite executeSql is not returning ResultSet

Time:10-16

I am attempting to perform a simple query with Sqlite in React-Native using the react-native-sqlite-storage plugin. Based on the documentation I should get two paramters into the success callback 1) the SQLite.Transaction and 2) SQLlite.ResultSet but I am only getting the SQLite.Transaction in my example.

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

Console output

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

CodePudding user response:

I forgot to wrap my executeSql in a transaction. This works as expected:

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