mercredi 24 février 2016

Update table with sqlite and angularjs

db = window.sqlitePlugin.openDatabase({name: "database.sqlite", createFromLocation: 1}, function () {
    alert("database created/opened successfully");
}, function (error) {
    alert("database create/open command failed with error: " + error);
});

 var statement = "";

db.transaction(function (tx) {

    statement = "select * from pictures where objectid='126'";
    tx.executeSql(statement, [], function (tx, res) {

        for(var i=0;i<res.rows.length;i++){

            $scope.DiamoniImagesArray[i]=res.rows.item(i);
            $scope.$apply();
        }
    }, function (e) {
        alert("Something went wrong");
        //alert("ERROR: " + JSON.stringify(e, null, 4));
    });

}, function (e) {
    alert('transaction error: ' + e.message);
});

i work with angularjs and cordova sqlite to build android application.The above code is work perfect.I have a problem when i have update statement like below:

var statement1 = "";
   $scope.DiamoniImagesArray1 = [];
db.transaction(function (tx) {



    statement1 = "UPDATE objects SET Favorites='1' where objectid='126'";
    tx.executeSql(statement, [], function (tx, res) {
     alert("change");

    }, function (e) {
        alert("Something went wrong");

    });

}, function (e) {
  alert('transaction error: ' + e.message);

}); 

The table object not update.Any suggestions?. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire