I try to create a common routine to use for queries in XData. Here's the (simplified) code:
function GetQueryString(Qry: IXDataQueryBuilder; Ds: TAureliusDataSet; Filter: string): string;
var FilterDateTime: TDateTime;
FilterInt: integer;
Filterfloat: Double;
begin
FilterDateTime := StrToDateTimeDef(Filter, MinDateTime);
FilterInt := StrToIntDef(Filter, -9999);
FilterFloat := StrToFloatDef(Filter, -9999);
if Filter.Trim <> '' then
for var col in DS.Fields do begin
if IsString then begin
case col.DataType of
ftString: Qry.Filter(Linq[col.FieldName].ILike('%'+Filter+'%'));
...
end;
end;
if IsInt then begin
case col.DataType of
ftSmallint: Qry.Filter(Linq[col.FieldName] = FilterInt);
...
end;
end;
if IsFloat then begin
case col.DataType of
ftFloat: Qry.Filter(Linq[col.FieldName] = FilterFloat);
...
end;
end;
if IsDateTime then begin
case col.DataType of
ftDateTime: Qry.Filter(Linq[col.FieldName] = FilterDateTime);
...
end;
end;
end;
Result := Qry.QueryString;
LogProxy.Log(llVerbose, Result);
The result is without logical operators (and, or):
I see several and words in your filter string. So I don't see why you say the result is without logical operators.
Now, it would be very convenient for everyone that you first try to debug your code, simplifying it to a smaller case, instead of throwing a big huge string of conditions that we don't even know where they come from, as there is no clue about how you are calling your code and also the code is missing parts (IsInt, etc.).
So please try to understand better your code and reduce it to a minimal (e..g, only two field comparisons) for better support.
then it works (I added 'eq' to the query). I Use Linq to create the query as shown in the documentation.
IsInt, IsFloat, IsString... Are helper functions just to see if the user typed string could be used to search appropriate fields. For example if the user inserts 'test', then is not necessary to search on TDateTime fields in the DB.
function GetQueryString(Qry: IXDataQueryBuilder; Ds: TAureliusDataSet; Filter: string): string;
begin
for var col in DS.Fields do begin
Qry.Filter(Linq[col.FieldName] = FilterInt);
end;
Result := Qry.QueryString;
I tried and your example works perfectly. But I found the problem. The error is on my side, because I used the points for subproperties instead of slashes. Example that does not work:
http://localhost:2001/easy/Partner?$filter=(Zip.Code eq '10e' or Zip.City eq '10e')
but this works:
http://localhost:2001/easy/Partner?$filter=(Zip/Code eq '10e' or Zip/City eq '10e')
But strangely, the error displayed is strange, because it's not related to the parenthesis, it's a syntax error.