In the Amalgamation Source search for the line (around 37836):

  dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;

If you change this to:

  dwShareMode = 0

then use this version of sqlite3.c in your application.  This will open the 
file for "exclusive" access and not shared access.  This means that the file 
will not be able to be read/written/deleted while your application has the file 
open.

"Locking Mode" is not the same as "ShareMode", and the standard library does 
not have the capability to open a database for exclusive (non-shared) access.

It should be noted that even if you open the file in exclusive (non-shared) 
mode, it can still be deleted or renamed while in use -- but the contents 
cannot be changed (or read) by another process while it is open.

---
Theory is when you know everything but nothing works.  Practice is when 
everything works but no one knows why.  Sometimes theory and practice are 
combined:  nothing works and no one knows why.

>-----Original Message-----
>From: sqlite-users-bounces at mailinglists.sqlite.org [mailto:sqlite-users-
>bounces at mailinglists.sqlite.org] On Behalf Of Fabian Pr?bstl
>Sent: Wednesday, 8 April, 2015 08:18
>To: sqlite-users at mailinglists.sqlite.org
>Subject: [sqlite] Prevent database file from being overwritten by other
>processes
>
>Hi there!
>
>Currently, we are using SQLite as our application file format for a
>Windows 7/C#/System.Data.SQLite based desktop application. We only allow
>one instance to open the file by running "set
>locking_mode=EXCLUSIVE;BEGIN EXCLUSIVE;COMMIT" when connecting to the
>database.
>
>This all works fine, however a user can still open Windows Explorer and
>copy paste a file with the same name but different content (e.g. an empty
>file) over an existing, exclusively locked database. From what I found
>out with the OpenedFilesView tool, SQLite seems to open the file with
>SHARED_WRITE, which explains why *any* process can overwrite the
>contents.
>
>Is there an easy way of configuring / changing this so that SHARED_WRITE
>is not acquired? Will SQLite even function? Is it just easier to create a
>hidden copy and work on that?
>
>Thanks for the advice
>Fabian
>_______________________________________________
>sqlite-users mailing list
>sqlite-users at mailinglists.sqlite.org
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



Reply via email to