views:

132

answers:

3

Hey Guys,

Is it possible to read from a SQLite db while it's being written to?

I'm aware that access is blocked for writes when it's being written to, but is that the same for reads?

+1  A: 

It's a little convoluted, but check out the File Locking and Concurrency documentation for SQLite. It sounds like if the db is in exclusive locked mode, that is the only time reads are not allowed. Besides unlocked, when the db is not even open.

I'm not 100% sure on it, but that's what I think it means.

Mark Rushakoff
A: 

Yes, although all the relevent multithreading issues need to be account for. I generally open multiple handles to the same DB file via sqlite3_open_v2().

Louis Gerbarg
A: 

After some reading around, and looking through the FMDB code, I discovered that I wasn't using the SQLITE_BUSY and SQLITE_LOCKED return values correctly.

According to the FMDB code, one should loop for a limited number of retries, waiting for a short time bewteen.

So I implemented that in my code, and everything seems to work fine.

Jasarien