Sqlite: read / write lock check

I have 2 processes that both have access to sqlite3 database. Although reading is not a problem in sqlite, only one process can write to the database. According to faq:   http://www.sqlite.org/faq.html#q5 sqlite uses read / write locks.

How to check if a database is locked for writing by another process, both from python and from C ++?

[edit] I mean, query execution is an option, but performance is required depending on the request. So the question is what type of request do I use to minimize this effect. I would also like to lock / unlock the database myself.

+3
source share
1 answer

When SQLite tries to access a locked database, the default is SQLITE_BUSY. The documentation describes how to add custom processing to this event: http://www.sqlite.org/faq.html#q5 .

I understand from the documentation that any function that you call that tries to write to this locked database will simply return SQLITE_BUSY, and this will be your notification that the database is locked.

, , (sqlite3_busy_handler) (sqlite3_busy_timeout), x .

[edit] http://www.sqlite.org/c3ref/io_methods.html , - xCheckReservedLock(), true, . , . - sqlite, . , : http://www.sqlite.org/c3ref/file_control.html

+2

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


All Articles