Board index » delphi » Lock record / Delphi 7 and SQL2000

Lock record / Delphi 7 and SQL2000


2004-08-06 12:52:31 AM
delphi139
Hi,
I want to lock record in my application when my ADOQuery.state is in dsEdit
I tried all the combinaison of LockType, CursorType, CursorLocation and
ConnectMode, but i don 't succeed.
My SQL statement is simple : select * from country
I launch my App twice. I modify a data on my first screen, i can modify the
same data with the second screen of my app !!!
How can i do to lock the record the first user modify, and prevent the
second user the data is not enabled ?
Thanks for your help
 
 

Re:Lock record / Delphi 7 and SQL2000

SQL is a shift from desktop databases, they use Optimistic as opposed to
Pessimistic locking, in other words, most SQL applications expect to handle
the problem AFTER they try to save..
From the old BDE, this was represented with UpdateKind..
UpWhereAll - Update would succeed if NONE of the Columns listed were changed
since grabbed.
UpWhereChanged - Update would succeed if NONE of the CHANGED Columns were
changed..
UpWhereKeyOnly - Update would succeed as long as the primary key hadn't
changed..
After a failure, "Um, User A, another user beat you to it, so we have to
abandon your changes!"
You can use semaphore locks, ie, roll your own, by tracking who has what in
a table system that you construct and maintain..
The most reliable way to implement pessimistic locking is to update the row
FIRST with a dummy statement (set a value to itself), prior to edit state,
which effectively locks the row until next commit or rollback. This affects
concurrency, however, as with the user that opens an edit screen, and heads
off to a 3 hour lunch..
Rob