Failed to read the 'insertId' property from 'SQLResultSet'

'm trying to fetch a list of clients from my database and display it as a listview, but when I run the app I get the following error:

Error: Failed to read the ‘insertId’ property from ‘SQLResultSet’: The query didn’t result in any rows being added.

Can’t see what I’m missing here, any help will be appreciated!

dbFactory.method = function findAll() {
        db.transaction(
            function(tx) {
                var sql = "SELECT (nome) as nomes FROM clientes";
                tx.executeSql(sql, [],
                    function(tx, results) {
                        var len = results.rows.length,
                            clientes = [],
                            i = 0;
                        for (; i < len; i = i + 1) {
                            clientes[i] = results.rows.item(i).nomes;
                            deferred.resolve(results);
                        }
                        log(clientes + ' rows found');

                    }
                );
            },txErrorHandler,
            function () {

            }
        );
        return deferred.promise;

    };

Controller:

.controller('ListaCtrl', function ($scope, dbFactory) {


        $scope.clientes = dbFactory.method();

        dbFactory.method().then(function(response){
            console.log(JSON.stringify(response));

        });

    });

html:

<ion-view view-title="Playlists" ng-app="starter">
  <ion-content>
    <ion-list ng-controller = "ListaCtrl">
      <ion-item ng-repeat="itens in clientes" >

          <p>{{itens.nome}}</p>

      </ion-item>
    </ion-list>

  </ion-content>
</ion-view>

Is in the wrong place…

dbFactory.method = function findAll() {
        db.transaction(
            function(tx) {
                var sql = "SELECT (nome) as nomes FROM clientes";
                tx.executeSql(sql, [],
                    function(tx, results) {
                        var len = results.rows.length,
                            clientes = [],
                            i = 0;
                        for (; i < len; i = i + 1) {
                            clientes[i] = results.rows.item(i).nomes;
                        }
                        log(clientes + ' rows found');
                        deferred.resolve(clientes);
                    }
                );
            },txErrorHandler,
            function () { }
        );
        return deferred.promise;
    };

@aaronksaunders Thank you man, the error is gone, but the names is not showing up yet, why, is there something wrong with my controller or my ng-repeat?

Try this change to your controller

.controller('ListaCtrl', function ($scope, dbFactory) {

    dbFactory.method().then(function(response){
        console.log(JSON.stringify(response));
        $scope.clientes = response;
    });
});
1 Like

@aaronksaunders Thank you man it is working now, can you check my other question please? http://stackoverflow.com/questions/28745907/ionic-sidemenu-showing-the-same-content-when-url-changes