开发者

How do we know the lock status of sqlite DB?

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?.


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.


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.


It probably didn't exist in 2011, but sqlite3_txn_state will do it today: https://www.sqlite.org/c3ref/txn_state.html

Unfortunately there doesn't seem to be a pragma, which is a problem because most sqlite language bindings don't give access to it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜