tags:

views:

44

answers:

1

I have 2 processes: 1 is writing to a sqlite database, 1 is reading from the same database. Occasioally, I get SQLITE_BUSY on my selects. Is this normal? Is their some option or way I could open the database so that it blocks until it CAN complete the query? (I tried the FULLMUTEX option on the open call but it appeared to have no effect).

+1  A: 

When SQLite needs to write, it locks the entire database so no other thread/process can read or write it. That's why your other process gets SQLITE_BUSY. For that reason, SQLite isn't that great if you need to have multiple threads/processes using the database at the same time. If you only have two processes, you can probably get away with it though.

As to the second part of your question, you can tell SQLite to retry with the sqlite3_busy_timeout function, like this:

sqlite3_busy_timeout(db, 100);  /* Retry for up to 100 ms */
Daniel Stutzbach