#1 2020-02-13 14:20:59

Zebedee
Member
Registered: 2019-01-11
Posts: 3

Minor bug in TSQLRestStorageInMemory.SearchField

Hello Everyone,
I was trying to search my in memory config data through SearchField, and it returned False whatever i tried first. Then i started debugging into mormot classes and realize, this function never set Result to True.

I am using NightlyBuild and here is original code:

function TSQLRestStorageInMemory.SearchField(const FieldName, FieldValue: RawUTF8; out ResultID: TIDDynArray): boolean;
var n, WhereField: integer;
    {$ifndef CPU64}i: integer;{$endif}
    Where: TList;
begin
  result := false;
  if (self=nil) or (fValue.Count=0) then
    exit;
  if IsRowID(pointer(FieldName)) then
    WhereField := SYNTABLESTATEMENTWHEREID else begin
    WhereField := fStoredClassRecordProps.Fields.IndexByName(FieldName);
    if WhereField<0 then
      exit;
    inc(WhereField); // FindWhereEqual() expects index = RTTI+1
  end;
  Where := TList.Create;
  try
    StorageLock(false,'SearchField');
    try
      n := FindWhereEqual(WhereField,FieldValue,AddIntegerDynArrayEvent,Where,0,0);
    finally
      StorageUnLock;
    end;
    if n=0 then
      exit;
    SetLength(ResultID,n);
    {$ifdef CPU64} // on x64 TList[]=Pointer does map an TID/Int64
    {$ifdef FPC}Move{$else}MoveFast{$endif}(Where.List[0],ResultID[0],n*SizeOf(TID));
    {$else}
    with Where do
      for i := 0 to Count-1 do
        ResultID[i] := PPtrIntArray(List)^[i];
    {$endif}
  finally
    Where.Free;
  end;
end;

It returns False but still fill ResultID array. I fixed my code but i thought you should know this problem.
Best regards

Offline

#2 2020-02-13 15:19:42

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

Re: Minor bug in TSQLRestStorageInMemory.SearchField

That's somewhat funny: I discovered this bug yesterday night doing some code review.

It should be fixed by https://synopse.info/fossil/info/26f50ca370

Offline

Board footer

Powered by FluxBB