views:

395

answers:

2

I'm developing an android app. It has multiple threads reading from and writing to the android SQLite db. I am receiving the following error:

SQLiteException: error code 5: database is locked

I understand the SQLite locks the entire db on inserting/updating, but these errors only seems to happen when inserting/updating while I'm running a select query. The select query returns a cursor which is being left open quite a wile (a few seconds some times) while I iterate over it. If the select query is not running, I never get the locks. I'm surprised that the select could be locking the db.... is this possible, or is something else going on?

What's the best way to avoid such locks?

Thanks

TAO

A: 

By avoiding leaving cursors open for "quite a while". If you can afford to have all your data in memory all at once, then do so.

If you can't, then try increasing the busy timeout.

dan04