Reading from a locked SQLite3 database

I am looking at a third party process SQLite database. It looks locked and has a * -journal file. What I do not know is that the lock is general or exclusive.

I hope to read from the database, even if it is currently blocked by this other process. I will only read from the database.

I am currently failing. I get the SQLITE_BUSY return code while a third-party process is running.

I looked at sqlite3_busy_handler, but this does not seem to be a solution. From what I understand, it only allows you to implement the retry mechanism. He does not seem to suggest simply ignoring the fact that the database is locked.

How to force SQLite to read from this database?

By the way, I'm currently using the FMDatabase API wrapper. It does not use sqlite3_busy_handler. It loops endlessly while it receives the SQLITE_BUSY return code.

+4
source share
1 answer

I have done some research on this, and it looks like there are some (very undesirable) options.

  • Kill the process in which the database is locked

This is probably not an option for you, and it is not for me either.

  • Copy the file and read the copy

This seems like the best solution to this problem. In my case, I am trying to read the sqlite Firefox database. Firefox seems to lock the file for extended periods of time, so I can't just wait.

Since you are copying a database file in real time, you may receive a damaged copy. I do not think there is a risk of corrupting the original (but I'm not sure about that).

Just copy the file in the shell, for example

copy original.sqlite copy.sqlite 

or

 cp original.sqlite copy.sqlite 

Then open as usual.

+1
source

Source: https://habr.com/ru/post/1301896/


All Articles