You are not logged in.
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
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