0

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?

3
  • 1
    Querying a table that is not being written to should produce the correct result every time assuming your using independent connections on each thread and you have not reconfigured the SQLite threading mode from the default. Can you provide a repeatable example of the problem? Commented Aug 16, 2022 at 13:58
  • @AlexK. - Actually I'm using the same connection in each thread. Is that a problem? Should that change anything? Commented Aug 16, 2022 at 14:10
  • 1
    You need to have a connection-per-thread, they cannot be shared. Commented Aug 16, 2022 at 14:13

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.