DEFAULT错误调用JayData

时间:2013-10-15 14:30:21

标签: javascript cordova jaydata

当我使用JayData和SQL Lite Provider添加或保存一些数据时(在手机间隙中)。我得到了以下错误:

DefaultError:DEFAULT ERROR CALLBACK!

异常 数据:参数[1] 0:SQLError 代码:0 消息:“语句回调引发异常或语句错误回调没有返回false” proto :SQLError ...... 长度:1 proto :对象 get stack:function(){[native code]} 消息:“DEFAULT ERROR CALLBACK!” 名称:“DefaultError” set stack:function(){[native code]} proto :对象  jaydata.min.js:53 Guard.raise jaydata.min.js:53 Uncaught DefaultError:DEFAULT ERROR CALLBACK!

然而,记录被添加/更新确定。不知道问题是什么......任何想法?

代码是:

//Entities:
var Task = $data.Entity.extend("$org.types.Task", {
    Id: { type: "int", key: true },
    TaskType: { type: String, required: false },
    StatusId: { type: "int", required: false },
    DateScheduled:  { type: Date, required: false },
    TimeSlot:  { type: String, required: false },
    LastUpdated:  { type: Date,required: false },
    TaskName:  { type: String, required: false },    
    SpecialInstructions:  { type: String},
    PropertyAddress:  { type: String, required: false },
    PropertyPostCode:  { type: String, required: false },
    PropertyType:  { type: String, required: false },
    NumberOfBedrooms:  { type: "int", required: false },
    HasGarage:  { type: Boolean, required: false },
    HasOutHouse:  { type: Boolean, required: false },
    IsReadyForReportGeneration: {type: Boolean},
    TaskStatus: {type: String},
    DateOfTaskDisplayName: {type: String}
});

//inside a look etc:

taskToUpdate.TaskType = task.TaskType;
                        taskToUpdate.StatusId = task.TaskStatusId;
                        taskToUpdate.TaskStatus = task.TaskStatus;
                        taskToUpdate.DateScheduled = task.Date;
                        taskToUpdate.TimeSlot = task.Time;
                        taskToUpdate.LastUpdated = new Date();
                        taskToUpdate.TaskName = "Job " + task.TaskId + " " + task.TaskType + " @" + task.AddressOfTask + ", " + task.PropertyPostCode;
                        taskToUpdate.SpecialInstructions = specialInstructions;
                        taskToUpdate.PropertyAddress = task.AddressOfTask;
                        taskToUpdate.PropertyPostCode = task.PropertyPostCode;
                        taskToUpdate.PropertyType = task.PropertyType;
                        taskToUpdate.NumberOfBedrooms = task.NumberOfBedrooms;
                        taskToUpdate.HasGarage = task.HasGarage;
                        taskToUpdate.HasOutHouse = task.HasOutHouse;
                        taskToUpdate.DateOfTaskDisplayName = task.DateOfTaskDisplayName,
                        taskToUpdate.IsReadyForReportGeneration = task.ReportReady;

                        if (result.length == 0) {
                            $org.context.Task.add(taskToUpdate);
                        }

                        rowsProcessed++;

                        if (rowsProcessed == rowsToProcess) {
                            $org.context.saveChanges({
                                success: function(db) {
                                    viewModel.messages.push({message:"Tasks saved to local device."});
                                    showNotificationInfo("Tasks saved to local device.");
                                    hideLoader();
                                }, error: function(err) {
                                    console.log(err);
                                    viewModel.messages.push({message:"Errors saving tasks: " + err});
                                    showNotificationError("Errors saving tasks: " + err);   
                                    hideLoader();
                                }
                            });  
                        }

2 个答案:

答案 0 :(得分:0)

问题似乎发生是因为您没有设置任何ID,以防您添加新记录。 解决这个问题很简单:

if (result.length == 0) {
  taskToUpdate.Id = task.Id;
  $org.context.Task.add(taskToUpdate);
}

答案 1 :(得分:0)

RIght事实证明我正在调用一个调用context.savechanges()的方法--logInfo(message)。

通过使用日志创建消息调用它,它导致错误...但是所有数据都保存好了所以我仍然有点不确定实际发生了什么......

我现在确保savechanges()仅在所有工作完成后调用,并且只调用一次...

感谢帮助人们......