多个更新语句抛出“无法打开" [英] multiple update statements throw "cannot open"
问题描述
当我尝试在 WinRT 中 SQLite 的同一个事务中对同一个表进行多次更新时,出现无法打开"异常.
I am getting a "cannot open" exception when I try to do multiple updates on the same table in the same transaction on SQLite in WinRT.
我为此用例创建了一个示例应用程序.下面是代码,单击第一个按钮,我在事务中创建一个表,单击另一个按钮,我尝试第二次更新相同的记录.在那里,它会引发无法打开"异常.
I have created a sample application for this use case. Below is code where on clicking the first button, I am creating a table in a transaction, and on clicking the other button, I am trying to update the same record a second time. There, it throws a "cannot open" exception.
应用代码:
private SQLiteConnection getConnection()
{
var connection = SQLiteConnectionPool.Shared.GetConnection(
new SQLiteConnectionString("sample.db", false));
return connection;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
SQLiteConnection con = getConnection();
con.BeginTransaction();
{
try
{
var command = new SQLiteCommand(con) {
CommandText =
@"create table konysyncMETAINFO (
id bigint not null,
versionnumber int,
lastserversynccontext nvarchar(1000),
filtervalue nvarchar(1000),
replaysequencenumber integer,
lastgeneratedid integer,
scopename nvarchar(100),
primary key (id))"
};
var xyz = (double)command.ExecuteNonQuery();
var command2 = new SQLiteCommand(con) {
CommandText =
@"insert into konysyncMETAINFO
(id,scopename,versionnumber,lastserversynccontext,
replaysequencenumber,lastgeneratedid)
values ('1','testscope','0','','0','-1')"
};
var xyz2 = (double)command2.ExecuteNonQuery();
var command3 = new SQLiteCommand(con) {
CommandText =
@"insert into konysyncMETAINFO
(id,scopename,versionnumber,lastserversynccontext,
replaysequencenumber,lastgeneratedid)
values ('2','testscope2','0','','0','-1')"
};
var xyz3 = (double)command3.ExecuteNonQuery();
con.Commit();
}
catch (Exception ex)
{
con.Rollback();
}
}
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
SQLiteConnection con = getConnection();
con.BeginTransaction();
{
try
{
var command = new SQLiteCommand(con) {
CommandText =
@"Update konysyncMETAINFO
set lastgeneratedid='4'
WHERE scopename = 'testscope'"
};
var xyz = (double)command.ExecuteNonQuery();
//var command2 = new SQLiteCommand(con) { CommandText = "insert into konysyncMETAINFO (id,scopename,versionnumber,lastserversynccontext,replaysequencenumber,lastgeneratedid) values ('3','testscope3','0','','0','-1')" };
//var xyz2 = (double)command2.ExecuteNonQuery();
var command3 = new SQLiteCommand(con) {
CommandText =
@"Update konysyncMETAINFO
set lastgeneratedid='3'
WHERE scopename = 'testscope'"
};
var xyz3 = (double)command3.ExecuteNonQuery();
con.Commit();
}
catch (Exception ex)
{
con.Rollback();
}
}
}
推荐答案
您可能偶然发现了 我在 sqlite-net 中的错误.我已经创建了 一个修复,它已经被拉回到主分支中,但是从那时起,NuGet 上就没有新的发布.您可以直接下载最新源并检查它是否能解决您的问题.
You've probably stumbled across the same bug in sqlite-net that I have. I've created a fix which has already been pulled back into the main fork but there hasn't been a new release on NuGet since then. You could download the latest sources directly and check if it fixes your problem.
这篇关于多个更新语句抛出“无法打开"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!