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_open_v2
.SQLITE_OPEN_READWRITE
modeSQLITE_OPEN_READONLY
modeIn 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 :)
Cause of the error Normally, the error occurs when two users try to run transactions on the same tables and change the content. SQLite engine finds it abnormal and locks the database. Now, the user cannot run more transactions.
SQLite Lock UsageBegins the transaction, locking the entire database for reading. Use this if you only want to read from the database. Begins the transaction, acquiring a "modify" lock. This is also known as a RESERVED lock.
Write-Ahead Log (WAL) Files. A write-ahead log or WAL file is used in place of a rollback journal when SQLite is operating in WAL mode. As with the rollback journal, the purpose of the WAL file is to implement atomic commit and rollback.
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...!!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With