Thread safety and table modification in SQLite3

Does SQLite3 thread safety correspond to different threads changing the same database table at the same time?

+4
source share
4 answers

No. SQLite does not support concurrent write access to the same database file. SQLite will simply lock one of the transactions until the other completes.

+6
source

note that if you use python, to access the sqlite3 connection from different threads you need to disable the check_same_thread argument, for example:

sqlite.connect (": memory:", check_same_thread = False)

as of May 24, 2010, docs omit this option. omission is indicated as an error here

+4
source

Not necessary. If sqlite3 is compiled using the thread safety macro (check via function

  int sqlite3_threadsafe (void) 
), you can try to access the same database from multiple threads without risk of damage. However, depending on the required locks, you may or may not really change the data (I do not believe sqlite3 supports row locking, which means that you will need to lock the table for writing). However, you can try; if one thread blocks, then it will automatically write as soon as another thread completes using DB.
+1
source

You can use SQLite in three different modes:

http://www.sqlite.org/threadsafe.html

If you decide to use multi-threaded mode or serialized mode, you can easily use SQLite in a multi-threaded application. In such situations, you can read all your threads at once. If you need to write at the same time, the open table will be automatically blocked for the current stream of letters and unlock after that (the next stream will wait (mutex) for its progress until the table is unlocked). In all these cases, you need to create a separate connection string for each stream (.NET Data.Sqlite.dll). If you use another implementation (for example, any wrapper for Android), sometimes different things.

+1
source

All Articles