sqlite3 database is getting locked

2019-02-19 10:28发布

I am creating an application with sqlite. I am performing all kind of task on the database Insert, Update, Delete, Select.

For that I open the database every time, Then execute my query using sqlite3_step() and after the result I use sqlite3_finalize() and sqlite3_close() methods. It is working well in most cases. I am not getting when its happening but some times my database gets locked with the same process I follow and some time it works.

I need to unlock database so even in any case my database get locked then I can unlock it or Plz guide me if I can check by code that my database is locked so I can replace my database with the resource database.

I am using webservice too so I don't have issue about data loss. Is it make sense if I replace my database if it get locked or if there is any way to unlock the database.

1条回答
你好瞎i
2楼-- · 2019-02-19 10:33

Open database once in the beginning. And close it in the end in AppWillterminate function. You are only consuming time by opening and closing it in every database function.

As far as database lock is concerned, it gets locked when some application is still using it and other application is trying to get its access.

This could be your app, or possibly the sqlite manager add-on of your firefox.

I faced same problem once and what i did was

  1. Disabled the option in sqlite add-on where it remembers the previously opened database.

  2. Restart xcode, simulator.

  3. Make a copy of the sqlite file (desktop), delete it from the project and then add in project again from desktop.

The last solution sounds weird, but i was mad that time.

I hope this could help you.

查看更多
登录 后发表回答