2011/6/30 Richard Hipp <d...@sqlite.org>

> > > I am writing a desktop application in which I want to have exclusive
> > rights.
> > > In this way I do not need to check if the data has changed when the
> user
> > of
> > > my program wants to change records. Is this possible?
> >
> > You can open a transaction as
> >
> > BEGIN EXCLUSIVE
> >
> > <http://www.sqlite.org/lang_transaction.html>
> >
> > "After a BEGIN EXCLUSIVE, no other database connection except for
> > read_uncommitted connections will be able to read the database and no
> other
> > connection without exception will be able to write the database until the
> > transaction is complete."
> >
> > This is how you do that sort of thing.  So what you do is …
> >
> > 1) BEGIN EXCLUSIVE
> > 2) Check the result code from step 1 and make sure you got the lock.
> > 3) Do SELECTs to check the conditions for your data change and decide
> what
> > to do.
> > 4) If the results of step suggest changes, make them.
> > 5) END
> >
> > It is extremely common to see programs where step 3 of the above is done
> > before step 1.  Obviously, from your question, you understand this.
> >
> > Note to SQLite experts: it's not clear to me at what level the exclusive
> > lock is maintained on the file.  If an app crashes in while an EXCLUSIVE
> > lock is held, is the lock released ?  Does this vary by platform ?
> >
>
> The BEGIN EXCLUSIVE...COMMIT technique shown above only gives you exclusive
> access in rollback mode.  If you select WAL mode, then BEGIN EXCLUSIVE
> makes
> you the exclusive writer, but other processes can continue to read.  To get
> exclusive access in WAL mode, use PRAGMA locking_mode=EXCLUSIVE.
>

Is good enough for me. My only problem is that between reading the data and
writing the changes, I want to be sure that no one  has changed the data.
For me that is enough. But it is good to know for when I want really
exclusive access.

Thanks. I am going to try it.

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

Reply via email to