Add option for a process exclusive mode to open files on Windows
Originally posted to https://system.data.sqlite.org/index.html/tktview/0b91277bb4e13c7c68bd When making calls to the Win32 CreateFile() function, SQLite appears to always set the file sharing parameter dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE which allows the file to be opened for shared access across processes. CreateFile() must be called with a dwShareMode = 0 in order to open the file in a true process exclusive access mode. See https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files for full details. A side effect of this behavior is even when SQLite is configured for EXCLUSIVE WAL mode, users are still able to copy open SQLite database files on Windows using Explorer or other means which can result in corrupt copies that befuddle end users. To avoid this for our use cases, we're currently having to rebuild our own custom version of SQLite which allows us to force dwShareMode = 0. We're reaching out and see if there would be any appetite to add an option to allow for a process exclusive file access mode in the upstream SQLite?
That option would necessarily be Windows-only, no?
There's no process-exclusive open() on *nix, is there?
Yes, the OP is referring to [a line down in SQLite's Windows-specific code]. The reason this question was bounced from the ticket forum for the System.Data.SQLite wrapper is that it potentially affects *all* Windows builds of SQLite, not just that one variant. : https://sqlite.org/src/file?udc=1&ln=on&ci=tip&name=src%2Fos_win.c
Yes, the OP is referring to a line down in SQLite's Windows-specific code.
The reason this question was bounced from the ticket tracker for the System.Data.SQLite wrapper by Joe Mistachkin to this forum is that it potentially affects all Windows builds of SQLite, not just that one variant.
I get that. That wasn't my point.
If surfaced as a public API option, it would be a Windows-only option,
since there's no equivalent on Linux/Unix (at least I think). I'm not against it,
I just wonder if there's precedent, and if there is, which one(s), that's all.
Couldn't the Windows VFS use the hook into the PRAGMA interface to set windows-specific options?
Yes, PRAGMAs and/or URI parameters are often used for setting options specific to a VFS.
(7) By Larry Brasfield (LarryBrasfield) on 2020-10-15 19:31:59 in reply to 1 [link] [source]
This checkin made today appears to be evidence of a mild appetite along the lines you suggest.
Glad to hear that. We appreciate the upstreaming of our exclusive file locking behavior on Windows.
Just checked sqlite 3.34.0. The exclusive parameter for URI filename mode seems to work on Windows, quite a nice addition. But both release history and the page about sqlite3_open_v2 probably lacks this information. I hope this can be fixed for others to know. Thanks
Just checked sqlite 3.34.0. The exclusive parameter for URI filename mode seems to work on Windows, quite a nice addition. But both release history and the page about sqlite3_open_v2 probably lack this information. I hope this can be fixed for others to know. Thanks