2013-10-15 44 views
0

当我使用JayData和SQL Lite Provider(在手机间隙中)添加或保存一些数据时。我得到follwing错误:JayData上的默认错误回拨返回

DefaultError:DEFAULT ERROR CALLBACK!

异常 数据:参数[1] 0:的SQLError 代码:0 消息: “该语句回调引发异常或声明错误回调没有返回假” :的SQLError .... .. length:1 proto:Object get stack:function(){[native code]} message:“DEFAULT ERROR CALLBACK!” 名: “DefaultError” 设置堆栈:功能(){[本地代码]} :对象 jaydata.min.js:53个 Guard.raise jaydata.min.js:53 未捕获DefaultError:默认的错误回电话!

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

的代码是:

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

你怎么实例taskToUpdate? –

+0

随着attachOrGet ...有趣的事情,它曾经工作正常,直到我改变了一些表定义..我也尝试使用dropAllTables选项,以检查它是否与模型更改有关的问题。 –

+0

将computed = true添加到定义Id将有助于确保您拥有独特的价值。这是否会改变行为? – Robesz

回答

0

右原来我打电话的方法--logInfo(消息)被调用context.savechanges()了。

通过调用这个与日志创建消息,这是造成错误......但所有的数据都保存好,所以我还是有点不确定什么怎么回事...

我VE现在确信的SaveChanges()所有工作完成后才能调用,只调用一次...

感谢帮忙的人......

0

这个问题似乎发生,因为你没有的情况下,添加新记录的任何标识集。 这种情况的解决方法是简单的:

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

抱歉应该放置这行代码:var taskToUpdate = $ org.context.Task.attachOrGet({Id:task.TaskId}); –