ngCordova SQLite how to make a simple select query

Forgive my ignorance, but I am struggling to make a simple select query with ngCordova SQLite. I can create the database and insert fine as per the example, but cannot retrieve the data from a select query.

I am currently trying:

var query = "SELECT * FROM reports WHERE ID=?";
$cordovaSQLite.execute(db, query, [1]).then(function(data) {
}, function (err) {

But all this gives me is the res information relating to rows affected.

Does anyone have the right method to get the actual row data rather than just the res data?



It returns an object with all the results, so you need to access it’s properties:

// or
for (var i = 0, i < res.rows.length; i++) {
   var id = data.rows.item(i).id;
   var name = data.rows.item(i).name;

If you need some more explanation this might help: Introducing Web SQL Databases

Hope this helps!


Thanks! That was it :slight_smile:

1 Like

how to show all created tables?
also is there a list of available queries ?

I would strongly recommend to visit this 100% full working App template that illustrates how to install a prepopulated SQLite database and do queries to retrieve information from there.

It also comes with other interesting plugins illustrates as part of its functionality:

 let fetch = ('select password from user where email='+email);
        this.db1.executeSql(fetch, {})

what is wrong in this query
this is what error I am getting
"message":“sqlite3_prepare_v2 failure: no such column: dsadsad”,“code”:5}

“dsadsad” -> my input at login page

This is just what I was looking for. Thanks! :smiley:

can you please tell me how to update data

$scope.redirectHome = function()

  var query = 'Update users set Project_Title=(?), Project_Description=(?) where id=(?)';
  $cordovaSQLite.execute(db,query,[ $rootScope.labels[0].value, $rootScope.labels[1].value ]).then(function(res){
				   alert('data successfully updated');
             }, function(err) {
               console.log("Updation Error");