#1 2016-10-30 07:48:15

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Update() and BatchUpdate() - Allow specifying update conditions?

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 smile

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

#2 2016-10-30 10:22:08

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,549
Website

Re: Update() and BatchUpdate() - Allow specifying update conditions?

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

#3 2016-10-30 18:20:05

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: Update() and BatchUpdate() - Allow specifying update conditions?

@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

Board footer

Powered by FluxBB