为什么 SQLite 给出“数据库已锁定”信息使用 Perl 的 DBD::SQLite 时事务中的第二个查询?
使用 Perl DBD::SQLite 时,SQLite 是否存在已知问题,会在单个事务中的第二个查询中给出“数据库已锁定”错误?场景:Linux、Perl DBI、AutoCommit => 0,具有两个代码块的子例程(使用代码块本地化变量名称)。在第一个代码块中,prepare() 在 select 语句上创建查询句柄,并执行它并关闭块。第二个代码块另一个查询句柄是通过准备更新语句创建的,并且经常(30% 的时间)SQLite/DBI 在此阶段给出数据库锁定错误。我认为错误发生在准备()期间而不是在执行()期间。
我的解决方法是在第一个查询后提交。 (对第一个查询调用 finish 没有帮助)。出于与优雅和性能相关的几个原因,我不愿意做出承诺。原始代码使用 Postgres 作为数据库多年来一直运行良好。我尝试了 sqlite_use_immediate_transaction 没有效果。
在所有其他情况下,我发现 SQLite 的性能都非常好,因此我怀疑这是 DBD 驱动程序的疏忽,而不是 SQLite 的问题。遗憾的是,我当前的代码是一大堆脚本和模块,因此我没有简短的单文件测试用例。
Is there a known problem with SQLite giving a "database is locked" error for a second query in a single transaction when using Perl DBD::SQLite? Scenario: Linux, Perl DBI, AutoCommit => 0, a subroutine with two code blocks (using the blocks to localize variable names). In the first code block a query handle is created by prepare() on a select statement, it is executed() and the block closed. The second code block another query handle is created by prepare for an update statement, and frequently (30% of the time) SQLite/DBI gives a database locked error at this stage. I think the error happens during prepare() and not during the execute().
My work around is to commit after the first query. ( Calling finish on the first query did not help). I prefer not to commit for several reasons relating to elegance and performance. The original code has worked fine for many years with Postgres as the database. I tried sqlite_use_immediate_transaction with no effect.
In all other situations, I've found SQLite to perform very well, so I suspect this is an oversight in the DBD driver, rather than an issue with SQLite. Sadly, my current code is a big pile of scripts and modules, so I don't have a short, single file test case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论如何与此无关的是: 事务和数据库从
DBD::SQLite
> 佩尔多克?Not related to this in anyway is it: Transaction and Database Locking from the
DBD::SQLite
perldoc?