redrom
redrom

Reputation: 11642

Cordova SQLlite plugin how to get values form select?

I just installed this SQLlite plugin for Cordova:

https://github.com/brodysoft/Cordova-SQLitePlugin

I would like to get returned results as JSON array, so i tried this:

 db.transaction(function(tx) {
     tx.executeSql("select * from dialed_calls;", [], function(tx, res) {
         console.log("tx object " +JSON.stringify(tx));
         console.log("res object " +JSON.stringify(res));
     });
 });

Problem is that none from returned objects contains response values from columns.

For example res object returns this:

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

Question is:

How can i get result with retuned rows as a JSON array?

Thanks for any help.

Upvotes: 0

Views: 3158

Answers (1)

redrom
redrom

Reputation: 11642

I solved it by this way:

db = window.sqlitePlugin.openDatabase({name:"callplanner"});
db.transaction(function(tx) {
    tx.executeSql('SELECT * FROM planned_calls', [], function(tx,results) {
        for (var i=0; i < results.rows.length; i++){
            row = results.rows.item(i);
            console.log("row is " + JSON.stringify(row));
        }
    });
});

Upvotes: 5

Related Questions