I have following piece of code, which should be able to log to console number of records (if table subjects exists).
db = openDatabase("myDatabase", "1.0", "", 200000);
db.transaction(function(tx) {
tx.executeSql("SELECT COUNT(*) AS nor FROM subjects", [],
function(result){
console.log(result.rows);
},
function(tx, error){
tx.executeSql("CREATE TABLE subjects (id REAL UNIQUE, name TEXT)");
}
);
});
Actually the result.rows is logging as undefined, so i even cannot call method item(int index) on it. How can i get access to number of returned records?
You forgot the
txparameter in your onSuccess callback function. Yourresultvariable actually is the transaction object.Here’s the corrected code: