Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is SQLite thread safe under this situation?

I require database access operations from several threads, through a singleton object, which holds a database connection. I read from SQLite3's website, saying that 'an sqlite3 structure could only be used in the same thread that called sqlite3_open() to create it. You could not open a database in one thread then pass the handle off to another thread for it to use'. I'm wondering under my situation, is there any threat of thread-unsafety?

like image 609
user26404 Avatar asked Dec 10 '08 03:12

user26404


People also ask

Is SQLite connection thread-safe?

In serialized mode, SQLite can be safely used by multiple threads with no restriction.

Is SQLite database secure?

SQLite engine do not have built-in security to protect databases, rather, it relies on its environment such as the operating system to provide security for database content. While Android provides security mechanisms for SQLite databases, it has been shown to be inadequate.

When should you not use SQLite?

A good rule of thumb is to avoid using SQLite in situations where the same database will be accessed directly (without an intervening application server) and simultaneously from many computers over a network. SQLite will normally work fine as the database backend to a website.

Is SQLite thread-safe python?

Is it safe to share an sqlite3 connection between threads? Yes, unless you change the default THREADSAFE option.


1 Answers

If the SQLite library is compiled with -DSQLITE_THREADSAFE you are OK with the more recent SQLite 3 versions.

The author of SQLite says:

Beginning with version 3.5.0, SQLite enforces this itself using its
own internal mutexes, so the application is free to (try to) use the
same database connection from multiple threads at the same time.

like image 126
Doug Currie Avatar answered Oct 01 '22 22:10

Doug Currie