Question

If I want to query (read) from an SQLite database using Haskell's HDBC across multiple threads, can I use a single connection, or should each thread have its own connection? Thanks.

Was it helpful?

Solution

I searched through the hdbc-sqlite code and found this comment:

Logic for handling counts of changes: look at the total changes before and after the query. If they differ, then look at the local changes. (The local change counter appears to not be updated unless really running a query that makes a change, according to the docs.)

This is OK thread-wise because SQLite doesn't support using a given dbh in more than one thread anyway.

The official Sqlite documentation has a whole page about this topic

The FAQ says:

(5) Can multiple applications or multiple instances of the same application access a single database file at the same time?

Multiple processes can have the same database open at the same time. Multiple processes can be doing a SELECT at the same time. But only one process can be making changes to the database at any moment in time, however.

This information would exclude both of your approaches. Perhaps you can write some tests for this to show that this information are wrong.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top