I am looking at a SQLite database owned by a third party process. It appears locked and has a *-journal file. What I don't know, is if the lock is shared or exclusive.
I am hoping to read from the database even though it is currently locked by that other process. I will only ever read from the database.
Currently I fail at this. I get a SQLITE_BUSY return code as long as the third party process is running.
I have looked at sqlite3_busy_handler, but that does not appear to be the solution. From what I understand that only allows for implementing a retry mechanism. It doesn't seem to offer a way to just ignore the fact, that the database is locked.
How can I force SQLite into reading from that database?
BTW, I am currently using the FMDatabase API wrapper. This does not use sqlite3_busy_handler. It loops endlessly as long as it gets a SQLITE_BUSY return code.
You should replace the backup database with the primary database. After the successful completion of the queries, the backup file will replace the locked database. As the backup file does not have any lock, it will be ready for the new transactions and queries by the user.
First, establish a connection to the SQLite database by creating a Connection object. Next, create a Cursor object using the cursor method of the Connection object. Then, execute a SELECT statement. After that, call the fetchall() method of the cursor object to fetch the data.
SQLite can still be made to work in many remote database situations, but a client/server solution will usually work better in that scenario.
I've been doing some research on this and it looks like there are some (very undesirable) options.
This probably isn't an option for you and it isn't for me either.
This seems to be the best solution to this problem. In my case I'm trying to read a Firefox sqlite database. Firefox appears to lock the file for long periods of time so I can't just wait.
Because you are copying a live database file you could get a corrupted copy. I don't think there is risk of corrupting the original (but I'm not sure about this).
Simply copy the file on the shell like
copy original.sqlite copy.sqlite
or
cp original.sqlite copy.sqlite
Then open as normal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With