当准备“选择”时,SQLite DB(具有WAL)被锁定。 statmement - 为什么? [英] SQLite DB (with WAL) locked when preparing a "select" statmement - why?
问题描述
我的设置:
p>- SQLite3数据库,journal_mode = WAL,synchronous = NORMAL
- 多个C ++进程使用数据库 - 这些进程中的任何方法都会用
sqlite3_open_v2
打开和关闭自己的非共享连接。 - 在
SQLITE_OPEN_READWRITE
模式中打开db - 从数据库读取的方法(即仅执行select语句) $ c> SQLITE_OPEN_READONLY 模式
在wAL模式下,我相信应该可以同时有读者,是一个写入。
然而我看到数据库被锁定当我准备一个select语句使用 sqlite3_prepare_v2
我可以做什么错误,导致读者被阻止?我误解了读实际上是什么?
任何提示赞赏,
感谢:)
检查每个sqlite3_step之后是否有sqlite3_reset,因为这是一种导致数据库被锁定的错误。
在使用sqlite3_prepare准备语句并使用sqlite3_step执行之后,您需要总是使用sqlite3_reset重置它。
sqlite3_reset S)接口将准备语句S重置为
程序的开始。
希望这解决了您的问题。 。!!!
I am seeing my reads getting blocked by the writes to the database which is in WAL mode - I'm stumped as to why.
My setup:
- SQLite3 database, journal_mode=WAL, synchronous=NORMAL
- Mulitple C++ processes (3 to be exact) use the database - Any method within these process open and close their own non-shared connection with
sqlite3_open_v2
. - Methods that are inserting data open the db in
SQLITE_OPEN_READWRITE
mode - Methods that read from the database (i.e. only do select statements) open the db in
SQLITE_OPEN_READONLY
mode
In WAL mode I believe it should be possible to have concurrent readers whilst there is a write occuring.
Yet I am seeing "database is locked" when I am preparing a select statement using sqlite3_prepare_v2
What could I be doing wrong which is causing the reader to get blocked? Am I misunderstanding what a "Read" actually is?
Any tips appreciated,
thanks :)
check whether you have sqlite3_reset after every sqlite3_step because this is one case that causes database is locked error. after preparing a statement with sqlite3_prepare and executing it with sqlite3_step,you need to always reset it with sqlite3_reset.
The sqlite3_reset(S) interface resets the prepared statement S back to the beginning of its program.
hope this solves your problem...!!!
这篇关于当准备“选择”时,SQLite DB(具有WAL)被锁定。 statmement - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!