SQLite C ++ database is locked when several processes access db in readonly mode

I have a sqlite database that does not change .

Several processes that open a database connection in SQLITE_OPEN_READONLY mode using sqlite3_open_v2. Each process is single-threaded.

Connections are made from the MSVC project, using the official C / C ++ Interface, one integrated C source file.

According to the SQLite FAQ, several SELECT processes are excellent

Each process after opening the database creates 4 prepared SELECT statements , each of which has 2 binding values.

During execution, agents (one at a time) have repeated calls as needed

  • sqlite3_bind_int
  • sqlite3_bind_int
  • sqlite3_step (when returning SQLITE_ROW)
  • sqlite3_column_int (while there was a row)
  • sqlite3_reset

Ready-made applications are reused, so finalization is not called for each of them until the end of the program. Finally, the database is closed at the very end of execution.

Problem Any of these operations may fail with error code = 5: 'database is locked'

Error code 5 is SQLITE_BUSY , and the website states that

"indicates a conflict with a separate database connection, possibly in a separate process"

The rest of the Internet seems to agree that several READONLY connections are OK. I went through the source and donโ€™t see that something is wrong (I canโ€™t post it sadly here, I know, itโ€™s not useful)

So, I appeal to you guys, what can I lose?

EDIT 1 : The database is on the local drive, the file system is NTFS, the OS is Windows 7.

EDIT 2 : Wrapping all sqlite3 calls in infinite loops that check if SQLITE_BUSY was returned and then redo the call fixes the problem. I do not consider this a correction, but if this is true, then I will do it.

+5
source share
1 answer

So the working answer I used is to wrap all sqlite calls in functions that loop this function when returning SQLITE_BUSY. There seems to be no easy alternative.

const int bindInt(sqlite3_stmt* stmt, int parameterIndex, int value) { int ret; do ret = sqlite3_bind_int(stmt, parameterIndex, value); while (ret == SQLITE_BUSY) return ret; } 
+2
source

Source: https://habr.com/ru/post/1204719/


All Articles