redrom
redrom

Reputation: 11642

Cordova-SQLitePlugin DB error on update

I'm using this plugin in my cordova app.

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

I have problem with syntax error during the update command:

"Error: a statement with no error handler failed: near "(": syntax error (code 1): , while compiling: UPDATE planned_call SET  (contact_name, number_to_call, date, note) = ('test','123456', '2014-12-06 16:42','test') WHERE planned_call.id = 5 ;",

What i'm doing wrong? Syntax of the SQL command seems to be right?

Thanks for any advice.

Syntax of the method is following:

   var sqlQuery = "UPDATE planned_call "+
                "SET  (contact_name, number_to_call, date, note) "+
                "= ('"+plannedCall.contact_name+"','"+plannedCall.number_to_call+"', '"+dateTimeOfCall+"','"+plannedCall.note+"') "+ 
                "WHERE planned_call.id = "+plannedCall.id+" ;";


            var db = window.sqlitePlugin.openDatabase({name:"callplanner"});
            db.transaction(function(tx) {
                // init empty array for results
                var plannedCalls = [];
                tx.executeSql(sqlQuery, [], function(tx,results){
                    $timeout(function() {
                        $scope.$apply(function() {
                            $ionicLoading.show({
                                template: $translate.instant('UPDATED'),
                                duration: 500
                            });
                            $scope.removeSchelduledAlarmNotification(plannedCall.id);
                            $scope.addSchelduledAlarmNotification(plannedCall.id, dateTimeOfCall, plannedCall.contact_name, plannedCall.number_to_call, plannedCall.note);
                            $state.go('planned-calls-today');
                        });
                    });

                });
            }, function(e){
                console.log(e);
                $ionicLoading.show({
                    template: $translate.instant('ERROR_DATABASE'),
                    duration:1000
                });
            });

Upvotes: 0

Views: 1351

Answers (1)

frank
frank

Reputation: 3330

The syntax for update in SQLite is

UPDATE table_name
SET column1 = value1, column2 = value2...., columnN = valueN
WHERE [condition];

so your update query should be

var sqlQuery = "UPDATE planned_call SET "
             + "contact_name   = '"   + plannedCall.contact_name    + "',"
             + "number_to_call  = '"  + plannedCall.number_to_call  + "',"
             + "date  = '"            + dateTimeOfCall              + "',"
             + "note  = '"            + plannedCall.note            + "'"              
             + "WHERE"
             +      "planned_call.id = " + plannedCall.id + " ;";

Upvotes: 2

Related Questions