Marcin L
Marcin L

Reputation: 83

sqlite3 in multi-thread mode: what exactly is unsafe to perform?

From the SQLite documentation article on multithreading I get that in Multi-thread mode "SQLite can be safely used by multiple threads provided that no single database connection is used simultaneously in two or more threads".

It doesn't explain though: exactly what is unsafe to do simultaneously in two or more threads in this mode? Apart from the obvious CREATE, INSERT, UPDATE, DROP etc. queries modifying the database,

  1. Is it also unsafe to perform SELECTs simultaneously?

And what about using statements (sqlite3_stmt)? Is it also unsafe to simultaneously use them if they are connected with the same database? Especially:

  1. preparing statements (sqlite3_prepare_v2)
  2. binding values (sqlite3_bind*)
  3. clearing bindings (sqlite3_clear_bindings)
  4. resetting statement (sqlite3_reset)
  5. opening/closing new connections to the same database in different threads (sqlite3_open_v2, sqlite3_close_v2)

Upvotes: 0

Views: 1210

Answers (1)

Colonel Thirty Two
Colonel Thirty Two

Reputation: 26569

From my understanding, any operation on the sqlite3 object from two or more threads at the same time is dangerous in multi-threaded mode. Same applies to sqlite3_stmt objects, since they are "part of" the sqlite3 object.

However, you can (and usually do) have more than one sqlite3 connection to the same database, even in different processes. SQLite will manage concurrency between them.

Upvotes: 1

Related Questions