SQLite DB (with WAL) locked while preparing "select" statmement - why?

I see that my reads are blocked by writing to the database, which is in WAL mode - I'm at a dead end why.

My setup:

  • SQLite3 database, journal_mode = WAL, synchronous = NORMAL
  • Mulitple C ++ processes (3, to be precise) use a database. Any method inside this process opens and closes its own non-shared connection with sqlite3_open_v2 .
  • Methods that insert data open db in SQLITE_OPEN_READWRITE mode
  • Methods that are read from the database (i.e. only for select statements) open db in SQLITE_OPEN_READONLY mode

In WAL mode, I believe it should be possible to have readers at the same time while there is a recording.

However, I see that the "database is locked" when I prepare the select statement using sqlite3_prepare_v2

What can I do wrong that makes the reader block? Do I really not understand what Reading is?

Any advice appreciated

thanks:)

+7
source share
1 answer

check if you have sqlite3_reset after each sqlite3_step, because this is one case that causes a database lock error. after preparing the statement with sqlite3_prepare and executing it with sqlite3_step, you always need to reset with sqlite3_reset.

The sqlite3_reset (S) interface resets the prepared S statement back to the beginning of its program.

hope this solves your problem ... !!!

0
source

All Articles