Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we know the lock status of sqlite DB?

Tags:

sqlite

locking

1)Is there a pragma or any way to know the current lock state of sqlite db?.
2)Also, Is there a way to know if any other process is using the DB?.

like image 789
asdfg Avatar asked Jan 07 '11 19:01

asdfg


2 Answers

No pragma, but the FAQ states:

When SQLite tries to access a file that is locked by another process, the default behavior is to return SQLITE_BUSY.

However, that only means the database is locked for writing, not reading.

like image 100
MPelletier Avatar answered Sep 28 '22 14:09

MPelletier


Regarding #1: No, because the answer you got would be immediately stale (that is if you got an answer of "no the database isn't locked", someone else could come along and immediately lock it, leaving you with bad info).

The correct approach is to simply try your operation (optionally with a timeout) and see if it succeeds.

like image 23
nobody Avatar answered Sep 28 '22 15:09

nobody