On Thu, Jul 28, 2011 at 11:49:34PM -0700, Jonathan Little scratched on the wall:
> I've been tearing my hair out over this for a little while, but I feel
> like there must be something simple I'm missing. Based on the behavior
> I'm seeing, the EXCLUSIVE locking mode isn't working the way I'd
> expect it to work based on the docs at
> http://www.sqlite.org/pragma.html#pragma_locking_mode.

> ...I can still read the file from other processes (e.g. I can copy it
> using a file manager UI). I cannot open it in another instance of 
> SQLite (as expected) but from the documentation I'd expect not to be
> able to read it from another process at all until the lock had been
> released somehow or the database closed.

  On many OSes and most filesystems, file locking is advisory, not
  mandatory.  File locks are essentially OS maintained atomic flags
  about the locking state of a file.  The application must explicitly
  check and acquire locks to understand if it is able to perform read/write
  operations on the file.

  In short, most file locking is about applications cooperatively
  waiting their turn, rather than being forcibly prohibited from doing
  things.  They're "locks" in the computer science sense of that
  word, not the front-door sense of the word.

  It also means that if an application (such as a file manager) does not
  understand the specifics of the locking scheme used with a file, or
  simply ignores locks, the application is usually free to manipulate
  the file however it wants.
  
    http://en.wikipedia.org/wiki/File_locking

> This behavior seems undesirable to me -- we've got users of our
> application copying the database file using Windows Explorer while
> it's being written to, and ending up with inconsistent/corrupt databases.

  Yes, well... that's true of almost any type of complex file format.

> Am I missing something here or if I want to prevent this, is my only
> option to modify our build of SQLite to open the file for exclusive access?

  You can set the file permissions.  That's a more appropriate means to
  prevent this kind of operation.

   -j

-- 
Jay A. Kreibich < J A Y  @  K R E I B I.C H >

"Intelligence is like underwear: it is important that you have it,
 but showing it to the wrong people has the tendency to make them
 feel uncomfortable." -- Angela Johnson
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to