Is it possible to check the threading mode of an active SQLite connection? I know about sqlite3_threadsafe()
, but
The return value of the sqlite3_threadsafe() function shows only the compile-time setting of thread safety, not any run-time changes to that setting made by sqlite3_config().
In serialized mode, SQLite can be safely used by multiple threads with no restriction.
The Android uses java locking mechanism to keep SQLite database access serialized. So, if multiple thread have one db instance, it always calls to the database in serialized manner and of course database is thread-safe.
The current version of SQLite handles multiple connections through its thread-mode options: single-thread, multi-thread, and serialized. Single-thread is the original SQLite processing mode, handling one transaction at a time, either a read or a write from one and only one connection.
If there is no outstanding transaction open then nothing happens. This means you do not need to worry too much about always closing the database before process exit, and that you should pay attention to transactions making sure to start them and commit at appropriate points.
Hmmm, seven year old question. You have answered it yourself, though. For the next person who comes looking:
sqlite3_db_mutex will return NULL if threading mode is Single-thread or Multi-thread.
So we have:
(sqlite3_threadsafe , sqlite3_db_mutex) : threading mode
(0 , NULL) : Single-thread
(1 , NULL) : Mutli-thread
(1 , valid) : Serialized
Here is a partial answer:
sqlite3_mutex *sqlite3_db_mutex(sqlite3*);
This interface returns a pointer the sqlite3_mutex object that serializes access to the database connection given in the argument when the threading mode is Serialized. If the threading mode is Single-thread or Multi-thread then this routine returns a NULL pointer.
Now I only need a way to distinguish Single-thread from Multi-thread...
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