SQLite 持久更新

SQLite Persist Update

我在 Windows UWP (10) 上使用 SQLite。

这就是我正在做的事情:

打开连接 开始交易 更新行 提交交易 关闭连接

然而,数据库中的值并未实际写入 table。当我重新加载记录时(在断开连接并重新连接后,或未断开连接后),该值在我调用更新之前仍然存在。

我还需要做些什么吗?在 SQLite 的数据库浏览器中,有一个名为 "Write Changes" 的菜单项。那有什么作用?只是一个普通的提交?在浏览器中,仅当我单击此菜单项时才会提交更改。

此外,我对连接进行了追踪,结果是这样的:

正在执行:开始交易

正在执行:更新 'TaskManagement.TaskInfo' 放 StatusKey = @StatusKey,ProbAddDttm = @ProbAddDttm,ProbCode = @ProbCode,ProbPriority = @ProbPriority,ProbGroup = @ProbGroup,ProbInsp = @ProbInsp,Activity = @Activity,UpdateDttm = @UpdateDttm,Asset = @Asset,地址 = @Address,TaskStartDttm = @TaskStartDttm,MaintenanceScheduleSetup = @MaintenanceScheduleSetup,MaintenanceScheduleBatch = @MaintenanceScheduleBatch,ProbZone = @ProbZone,ProbContractor = @ProbContractor,ProbNotes = @ProbNotes,JobCompleted = @JobCompleted,Resolution = @Resolution,Result = @Result,ActType = @ActType,投诉 = @Complaint,BudgetNo = @BudgetNo,承包商 = @Contractor,MapLocCorrect = @MapLocCorrect,FollowUpWorkRequired = @FollowUpWorkRequired,条件 = @Condition,ActPriority = @ActPriority,预期版本 = @ExpectedVersion,EmailProbOriginator = @EmailProbOriginator,IsBug = @IsBug,IsCompletePendingCheckIn = @IsCompletePendingCheckIn 在哪里 TaskInfoKey = @PrimaryKey 0: 63711ec4-57d0-4a23-8595-0022b757af44 1:6 2: 2013-06-03 08:56:39:117 3:13 4:2 5:17 6:24 7: 8: 2015-11-10 04:05:09:502 9: 10: 11: 2013-06-03 08:56:39:117 12: 13: 14: 15: 16:测试这个mofo! 17: 2013-08-15 12:13:24:620 18: 19: 20: 21: 22: 23:4 24:错误 25:错误 26: 27: 28:3 29:错误 30:错误 31: 错误

正在执行:提交

所以,最后,问题是我没有正确地将参数传递给库。连接的 CreateCommand 方法只允许您传入命令文本和对象数组。这是不正确的,因为这意味着您无法命名参数。因此,我认为这是 UWP 的 SQLite 特定实现中缺少的功能。

其次,这应该是错误的! None 我上面提到的参数名称被传递给命令,但是当我 运行 它时,没有抛出异常。所以,我认为这是实现中的第二个错误。

我是这样修复的:

        var command = _Connection.CreateCommand(commandText, new object[0]);

        if (parameters != null)
        {
            foreach (var parameter in parameters)
            {

                if (parameter.ParameterValue is DateTime)
                {
                    parameter.ParameterValue = ((DateTime)parameter.ParameterValue).ToString("yyyy-MM-dd hh:mm:ss:fff");
                }

                command.Bind(parameter.ParameterName, parameter.ParameterValue);
            }
        }

        return command;