mardi 6 octobre 2015

cordova sqlite query rows length > 0 but items throws exception

I have a simple database that is built and filled with data, i have extracted the database from the device and examined it, it is correct, however when i query the database in with the cordova plugin(http://ift.tt/1O3yCJy), I have in the logs this:

"{"rows":{"length":15},"rowsAffected":0}"

which indicates that the query has successfully found the records. but when i use the items function to get the results, it throws an exception, the following code is fired after the device is ready and the database is made, and filled.

var dataBase = window.sqlitePlugin.openDatabase({name: "database.sqlite"});
            dataBase.transaction(function(db) {
                db.executeSql("select * from Settings;", [], function(db, res) {
                    if(res.rows.length > 0) {
                        try{
                            console.log(JSON.stringify(res));
                            alert("RowsObject"+JSON.stringify(res.rows.items(0)));
                        }
                        catch(e){
                            alert("failed get results from query"+JSON.stringify(e));
                        }
                     }
                }, function(db, e){
                    console.log("error in sql:"+JSON.stringify(e));
                });
            });

Aucun commentaire:

Enregistrer un commentaire