You are not logged in.
Hello Arnaud,
How about adding a new parameter for specifying the condition when updating a record?
Something like:
Var
bat: TSQLRestBatch;
myRec: TSQLOrder;
oldTimeStamp: TDateTime;
begin
FDb.Retrieve(myRec...);
// remember the original timestamp of the record we are updating.
oldTimeStamp := myRec.LastUpdateTime;
// Here we use the record's original timestamp to **avoid** overwriting other users' edits.
bat.Update(myRec, 'LastUpdateTime = ?', [oldTimeStamp]);
...
end;
Does it make any sense
Last edited by edwinsn (2016-10-30 07:48:59)
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
Actually you propose a optimistic locking mechanism. But in this case we also must know dose record actually modified, for example to notify a user "record is modified by another user" etc. IMHO better to implement optimistic lock in business logic,
If myRec.lastUpdateTime <> oldTimeStamp do
Log unsuccessfully operation
Notify user record was modified
Your rules
Else
Do actual update
But In this case we can't use a batch..
Last edited by mpv (2016-10-30 18:28:56)
Offline
@mpv,
Sorry, I'm not sure if I follow you...
All I want is to make sure the update **will fail** if the record's modified by another user.
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline