sqlite error database is locked

后端 未结 8 1135
天命终不由人
天命终不由人 2020-12-06 08:00

I am have a sqlite database in the iPhone application I am writing. I get an error with following code that I am running in a background thread. In the background thread, I

相关标签:
8条回答
  • 2020-12-06 08:42

    Your database is open. Close it using sqlite3_close(db).

    If you don't close, then the process accessing your database will be running background which will cause database is locked error.

    0 讨论(0)
  • 2020-12-06 08:49

    But note that if you access the same SQLite DB from multiple threads, without some sort of separate synchronization (some way to know that you'll never have near-simultaneous accesses from multiple threads) then you're likely to get "database locked" errors even if you close everything correctly on each access.

    SQLite does not provide any sort of "lock wait" mechanism.

    Your basic options are:

    1. Do all accesses from one thread.
    2. Use a separate lock protocol around all accesses.
    3. If you get a "database locked" error wait a brief period of time and retry.
    0 讨论(0)
提交回复
热议问题