SQLite3 wrong values when multithreading

Question:

this is a general question:
I’m using an sqlite3 DB and running a python program that changes, reads and writes to that DB.

I’m running the following command:

SELECT COUNT(*) FROM table WHERE prm1='a' AND prm2='b' prm3=12345;

When I run it regularly, it results the correct answer.

But when I run it multithreaded-ly, it results with different answers (sometimes it’s correct, but sometimes wrong).
Just for clarification: No write is being done in the meantime.

Are there any problems with running SQL commands simultaniously that I’m unaware of?

Asked By: urie

||

Answers:

When using multithreading and querying the SQL table, you CANNOT use the same connection and need to open a new connection per each thread.

Answered By: urie
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.