How do we know the lock status of sqlite DB?

蓝咒 提交于 2019-12-07 04:23:11

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4629242/how-do-we-know-the-lock-status-of-sqlite-db

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!