Do I need to block concurrent SQLite access for SELECT statements?

I am using FMDB to access standard iOS internal SQLite database, with one db connection shared by multiple threads.

To make it thread safe, I block access to the db one block of code at a time. Everything works well, although db access is a bit of a bottleneck now, obviously.

My question is, can I ease this a bit by allowing concurrent requests from multiple threads if they are all read-only SELECT operations?

I cannot find the answer anywhere.

+3


source to share


2 answers


You cannot use the same connection to execute multiple requests at the same time.



However, for pure read-only access, you can use multiple connections.

+3


source


You can have one object FMDatabase

per thread. You may need to write code to authenticate the free / busy terms and handle it correctly. For example, set one busyRetryTimeout

that is appropriate for your situation (for example, how long you want it to repeat in conflict situations). It is also graceful to handle if the timeout is running out and the database query fails.



Obviously using shared FMDatabaseQueue

is the easiest way to interact with databases from multiple threads. See Section Using FMDatabaseQueue and Thread Safety Section in FMDB README

.

+1


source







All Articles