Hauptmann Peter <hauptma...@yahoo.com> wrote:
> Is there a way to exclusively *open* a SQlite database, so that (a) open 
> fails if there is another connection to the database and
> (b) no other connections can be opened?

No. But you can start an exclusive transaction (execute a BEGIN EXCLUSIVE 
statement) right after opening the connection.

> I figured out already that I can get almost that by opening the database, 
> setting PRAGMA locking_mode=exclusive; and doing a
> dummy-write to the DB. However, this allows other clients to open / have open 
> the file, and for them it seems not possible to
> tell whether requests are rejected because of thsi exclusive access or just 
> because the database is currently busy.

These are not two distinct conditions, they are two ways to phrase the same 
condition. A statement "the database is currently busy" is equivalent to "some 
connection holds a lock on the database which is incompatible with a lock you 
are trying to obtain".

> Purpose: I want the option for one user to open the DB exclusively, and 
> reject all other connections immediately with "Someone
> else has opened this file exclusively"

You'll have to arrange that by some application-specific means.
-- 
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to