#1 2017-09-14 12:59:41

oz
Member
Registered: 2015-09-02
Posts: 98

Issue & Fix: TSQLRecordMany.ManyAdd() using TSQLRestBatch

Hi Arnaud,

there's an issue with TSQLRecordMany.ManyAdd() when used via TSQLRestBatch.
Current code:

function TSQLRecordMany.ManyAdd(aClient: TSQLRest; aSourceID, aDestID: TID;
  NoDuplicates: boolean; aUseBatch: TSQLRestBatch): boolean;
begin
  result := false;
  if (self=nil) or (aClient=nil) or (aSourceID=0) or (aDestID=0) or
     (fSourceID=nil) or (fDestID=nil) then
    exit; // invalid parameters
  if NoDuplicates and
     (InternalIDFromSourceDest(aClient,aSourceID,aDestID)<>0) then
      exit; // this TRecordReference pair already exists
  fSourceID^ := aSourceID;
  fDestID^ := aDestID;
  if aUseBatch<>nil then
    result := aUseBatch.Add(self,true)<>0 else   // Issue here
    result := aClient.Add(self,true)<>0;
end;

aUseBatch.Add returns the batch index or -1 on error, but code is checking for <> 0, so its always false for the 1st element.
Fix:

function TSQLRecordMany.ManyAdd(aClient: TSQLRest; aSourceID, aDestID: TID;
  NoDuplicates: boolean; aUseBatch: TSQLRestBatch): boolean;
begin
  result := false;
  if (self=nil) or (aClient=nil) or (aSourceID=0) or (aDestID=0) or
     (fSourceID=nil) or (fDestID=nil) then
    exit; // invalid parameters
  if NoDuplicates and
     (InternalIDFromSourceDest(aClient,aSourceID,aDestID)<>0) then
      exit; // this TRecordReference pair already exists
  fSourceID^ := aSourceID;
  fDestID^ := aDestID;
  if aUseBatch<>nil then
    result := aUseBatch.Add(self,true)<>-1 else   // Fix
    result := aClient.Add(self,true)<>0;
end;

Could you apply this fix to current sources please?!

Thanks,
oz.

Offline

#2 2018-04-17 14:34:39

oz
Member
Registered: 2015-09-02
Posts: 98

Re: Issue & Fix: TSQLRecordMany.ManyAdd() using TSQLRestBatch

@ab: is there any chance to apply this little fix?

Offline

#3 2018-04-17 14:40:05

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Issue & Fix: TSQLRecordMany.ManyAdd() using TSQLRestBatch

Please check https://synopse.info/fossil/info/9deb91e6c9

Sorry for the delay.

Offline

#4 2018-04-17 14:44:42

oz
Member
Registered: 2015-09-02
Posts: 98

Re: Issue & Fix: TSQLRecordMany.ManyAdd() using TSQLRestBatch

Thanks Arnaud!

Offline

Board footer

Powered by FluxBB