Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread Q: locking and transactions
Mon, May 22 2006 6:48 AMPermanent Link

"Ulrich Kobsa"
Hi,

I try to understand transactions and locking in DBISAM C/S mode and now
I have a question: Two clients executing a sql command (DBISAMQuery) to
update the *same* record on a table. I have encapsulated the update
with an explicit transaction. Commit is done explicitly on user request:

- first client starts transaction and updates the table
- second client starts transaction and updates the table
- now only first client can commit its transaction (say: press a button
to commit) while the second client is locked (in the sense: cannot
press a button to commit; I think its waiting to get the lock on the
record, right?)
- first client commits
- second client can now press button to commit its transaction

now the questions:
- why I don't get an error on the second client that he can't get a
lock for the record (Protocol=lpOptimistic, WaitTime = 100, Retries =
15) when waiting some time
- when the second client commits: shouldn't an error be raised that the
record has been changed by another user?

here's the code for the update acction:

with TDBISAMQuery.Create(nil) do
 try
   SessionName := dmClient.DBSession.SessionName;
   DatabaseName := dmClient.DBDatabase.DatabaseName;

   SQL.Text := 'update items set sectionid = '+cxTextEdit1.Text +
     ' where id = 5733';

   dmClient.DBDatabase.StartTransaction();
   try
     ExecSQL;
   except
     on E: Exception do
     begin
       ShowMessage(E.Message);
       dmClient.DBDatabase.Rollback;
     end;
   end;
 finally
   Free;
 end;

and here the one for commiting:

dmClient.DBDatabase.Commit(true);



Thanks,
Ulrich

Mon, May 22 2006 11:39 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Ulrich,

<< - why I don't get an error on the second client that he can't get a lock
for the record (Protocol=lpOptimistic, WaitTime = 100, Retries =
> 15) when waiting some time- when the second client commits: shouldn't an
> error be raised that the record has been changed by another  user? >>

Read this part of the manual regarding how DBISAM performs transaction
locking:

http://www.elevatesoft.com/dbisam4d5_transactions.htm

"Locking During a Transaction"

--
Tim Young
Elevate Software
www.elevatesoft.com

Image