On Wed, 23 Sep 2015 18:01:47 +0200 Michael Schlenker <msc at contact.de> wrote:
> Hi, > > i just wondered if there is an API to detect if a sqlite database file > is already opened by another process. > > I can make the assumptions that: > > 1. WAL mode is in use > 2. Linux and Windows only > 3. No network filesystems > 4. I only care if the access is done by another SQLite library, > not simple open() calls. > > I didn't see any explicit API to check for this, but assumed there > might be some way to find out via the .shm files? > > Usecase is a server process that keeps an SQLite DB open while it is > running and a commandline tool that manipulates the same DB file for > maintenance tasks. The maintenance tool should not change the DB if > the server is running. > > I could of course do explicit locking via other means to mediate > access (actually i do that now, but it is not really elegant), but if > there is an SQLite API way to do it, it would be nicer. > > Any good hints? If the other process is yours, you can use pragma user_version to store a reference counte of the number of times the db is opened, increasing each time you open it and decreasing each time you close it. > > Michael --- --- Eduardo Morras <emorrasg at yahoo.es>