0

当我添加或保存一些关于使用 JayData 和 SQL Lite Provider 的数据时(在电话间隙中)。我收到以下错误:

默认错误:默认错误回调!

异常数据:参数 [1] 0:SQLError 代码:0 消息:“语句回调引发异常或语句错误回调未返回 false” proto:SQLError ......长度:1 proto:对象获取堆栈:函数() { [本机代码] } 消息:“默认错误回调!” 名称:“DefaultError”设置堆栈:函数(){[本机代码]} 原型:对象jaydata.min.js:53 Guard.raise jaydata.min.js:53未捕获的默认错误:默认错误回调!

但是记录添加/更新正常。不知道问题可能是什么......有什么想法吗?

代码是:

//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();
                                }
                            });  
                        }
4

2 回答 2

0

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

if (result.length == 0) {
  taskToUpdate.Id = task.Id;
  $org.context.Task.add(taskToUpdate);
}
于 2013-10-25T17:27:54.017 回答
0

对了,原来我正在调用一个方法 --logInfo(message),它也在调用 context.savechanges()。

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

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

感谢您帮助人们...

于 2013-10-31T10:46:23.917 回答