Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if SQLite database is locked

I have an app that makes quite a few calls to a local SQLite3 database and sometimes these calls happen very close together (from different areas of the app). How can I check, before a call to the database is made, if the database is currently locked?

Ideally I would rewrite the app (which has grown far beyond its original scope) but won't have time in this iteration.

like image 479
Agamemnon Avatar asked Oct 30 '25 23:10

Agamemnon


1 Answers

I have no idea what to do in objective-c, but I have been using sqlite3 with c from quite long time And I also faced same issue. I used below method.

  1. use busy_timeout and keep it configurable.
  2. use busy_handler to keep retry for n number of time.

This two improvement works well for me, but I had observed some performance issue which i am able to handle via above configuration parameter. You need to do some trade of between fail-safe and performance.

like image 109
Manthan Tilva Avatar answered Nov 02 '25 23:11

Manthan Tilva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!