Page 1 of 1
Locking a table record as opposed to a query
Posted: Thu 11 Oct 2012 15:56
by mskeels
Can someone please point me to an example of Delphi code that uses locking in concert with an edit?
I found an example for a query.......but still not sure if that applies directly to a table.
Thanks,
Mark
Re: Locking a table record as opposed to a query
Posted: Fri 12 Oct 2012 07:37
by AndreyZ
Hello,
To use locking, you should use the LockMode property of a dataset (TMSQuery or TMSTable). If LockMode is set not to the lmNone default value, SDAC performs locking on records editing. Here is a code example:
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
begin
MSTable1.TableName := 'tablename';
MSTable1.LockMode := lmPessimistic;
MSTable1.Open;
MSTable1.Edit; // because LockMode is lmPessimistic, here SDAC locks the current record
MSTable1.FieldByName('fieldname').AsString := 'test';
MSTable1.Post; // here the current record is unlocked
end;
For more information about the LockMode property, please refer to the SDAC documentation.
Re: Locking a table record as opposed to a query
Posted: Mon 15 Oct 2012 13:14
by mskeels
Thanks so much for the reply.
A further question: will the following work with the table edit lock:
mstbl.Connection.ExecSQL('SET LOCK_TIMEOUT 10000', []);
Thanks,
Mark
Re: Locking a table record as opposed to a query
Posted: Mon 15 Oct 2012 14:31
by AndreyZ
Yes, it will work. Please note that SDAC sets LOCK_TIMEOUT to 2000 by default. You can control this using the TMSConnection.Options.DefaultLockTimeout property.
Re: Locking a table record as opposed to a query
Posted: Mon 15 Oct 2012 14:39
by mskeels
I appreciate the helpful and timely responses; thanks.
Mark
Re: Locking a table record as opposed to a query
Posted: Tue 16 Oct 2012 09:04
by AndreyZ
If any other questions come up, please contact us.