【问题标题】:Cordova-SQLitePlugin DB error on update更新时 Cordova-SQLitePlugin 数据库错误
【发布时间】:2015-02-04 16:11:23
【问题描述】:

我在我的 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
                });
            });

【问题讨论】:

    标签: sql sqlite cordova


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-30
      • 1970-01-01
      • 2017-02-03
      • 2020-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多