SQLite总是回复"database table is locked"

SQLite always replies with "database table is locked"

本文关键字:table is locked database SQLite 回复      更新时间:2023-10-16

如果我在C++程序中执行这些语句(%s代表一个选择语句,它可以变化,请假设%s没有错误)。

BEGIN TRANSACTION;
CREATE TEMP TABLE tmp AS %s;
DROP TABLE tmp;
COMMIT;

然后 sqlite3 总是用 database table is locked 回复,除非我不在最后删除表。语句使用 sqlite3_exec() 执行。网上还有其他类似的问题,但没有答案,例如:

http://sqlite.1065341.n5.nabble.com/How-is-the-table-getting-locked-and-how-to-unlock-it-td58324.html

我怀疑PRAGMA journal_mode=WAL;PRAGMA synchronous=OFF;是罪魁祸首,但我不确定。另外,也许逐个执行和完成语句也可能起作用?我可以检查表当前是否已锁定吗?

您正在使用sqlite3_enable_shared_cache()SQLITE_OPEN_SHAREDCACHE。 – CL.