ODATA Operators

Hello,

Where can I find which capabilities are ODATA implementation in DataAbstract.

Is there an operator like in SQL: StartWith or LIKE?

Best regards,
Tiberiu Stoicescu

Logged as bugs://D19292.

Logged as bugs://D19293.

Hi,

as a temporary workaround, pls update uDAOData.pas as

function TDAODataCall.GenerateSQLWhere(aSchema: TDADataset; AWhereBuilder: TDAWhereBuilder): TDAWhereExpression;
var
  l_left, l_right: TDAWhereExpression;
begin
  if (fName = 'startswith') and (fArguments.Count = 2) then begin
    l_left := fArguments[1].GenerateSQLWhere(aSchema, AWhereBuilder);
    l_right := fArguments[0].GenerateSQLWhere(aSchema, AWhereBuilder);
    if l_right is TDAConstantExpression then
      TDAConstantExpression(l_right).Value := VarToStr(TDAConstantExpression(l_right).Value)+'%'
    else
      raise EDAODataException.Create('1st element should be value');

    Result := AWhereBuilder.NewBinaryExpression(l_left, l_right, dboLike);
    Exit;
  end;


  raise EDAODataException.Create(err_CallsNotSupportedByDASQLInOdataFilters);
end;

and use filter like

http://localhost:8099/odata/Vendors/?$filter=startswith('Ge',Name)
1 Like

Hi,

I’ve mistaken - I’ve mixed arguments :frowning:

correct syntax is

bool startswith(string string, string prefixString)

and

startswith(CompanyName,'Alfr')

so code should be

function TDAODataCall.GenerateSQLWhere(aSchema: TDADataset; AWhereBuilder: TDAWhereBuilder): TDAWhereExpression;
var
  l_left, l_right: TDAWhereExpression;
begin
  if (fName = 'startswith') and (fArguments.Count = 2) then begin
    l_left := fArguments[0].GenerateSQLWhere(aSchema, AWhereBuilder);
    l_right := fArguments[1].GenerateSQLWhere(aSchema, AWhereBuilder);
    if l_right is TDAConstantExpression then
      TDAConstantExpression(l_right).Value := VarToStr(TDAConstantExpression(l_right).Value)+'%'
    else
      raise EDAODataException.Create('2nd element should be value');

    Result := AWhereBuilder.NewBinaryExpression(l_left, l_right, dboLike);
    Exit;
  end;

  raise EDAODataException.Create(err_CallsNotSupportedByDASQLInOdataFilters);
end;

and

http://localhost:8099/odata/Vendors/?$filter=startswith(Name,'Ge')

bugs://D19292 was closed as fixed.

check the Data Abstract for Delphi vNext: New features thread too

bugs://D19293 was closed as fixed.

1 Like