I
I
Ivan2020-11-17 16:45:05
Python
Ivan, 2020-11-17 16:45:05

How to change the value of SQLITE_THREADSAFE?

How to set SQLITE_THREADSAFE mode to 2? Through pragma? Maybe a special function?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2020-11-17
@mlneko

https://sqlite.org/howtocompile.html

S
Sergey Karbivnichy, 2020-11-17
@hottabxp

Using SQLite in Multithreaded Applications
SQLite can be compiled in single threaded mode (compile option SQLITE_THREADSAFE = 0).
In this variant, it cannot be used simultaneously from multiple threads, since there is no synchronization code at all. What for? For breakneck speed.
You can check if there is multithreading by calling sqlite3_threadsafe(): if it returns 0, then this is a single-threaded SQLite.
By default, SQLite is built with thread support (sqlite3.dll).
There are two ways to use multi-threaded SQLite: serialized and multi-thread.
Serialized(you must specify the SQLITE_OPEN_FULLMUTEX flag when opening the connection). In this mode, threads can pull SQLite calls as they please, no restrictions. But all calls block each other and are processed strictly sequentially.
Multi-thread (SQLITE_OPEN_NOMUTEX). In this mode, you cannot use the same connection from multiple threads at the same time (but different threads can use different connections at the same time). This mode is usually used.

SQLite is a great embeddable database (part 3)
May need a rebuild. But there is nothing complicated.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question