更新时Cordova-SQLitePlugin数据库错误

时间:2014-12-06 16:22:30

标签: sql sqlite cordova

我在我的cordova应用程序中使用此插件。

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

我在更新命令期间遇到语法错误问题:

"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 ;",

我做错了什么? SQL命令的语法似乎是对的?

感谢您的任何建议。

该方法的语法如下:

   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
                });
            });

1 个答案:

答案 0 :(得分:2)

SQLite中的更新语法是

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

所以你的更新查询应该是

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 + " ;";