Delphi REST-如何知道何时全部检索数据?

时间:2018-08-17 13:18:27

标签: rest delphi

在Delphi Tokyo中,我绑定了一系列REST组件(Delphi随附的组件:RESTClientRESTRequestRESTResponseRESTAdapater)一起检索REST数据。

在服务器上定义的REST调用将分页设置为某个值。
因此,在我的Delphi应用程序中,我必须反复更新RESTRequest

ResourceSuffix添加'?page =',然后添加页码。
由于各种REST服务可能具有不同的分页,或具有不同的结果行计数。
我怎么知道何时检索到所有数据?

当然,还有一些更优雅的方法,可以一直尝试到检索到的行= 0 /某些错误为止。

1 个答案:

答案 0 :(得分:0)

我找到了一个适用于我的解决方案...我的数据来自Oracle RDBMS,通过ORDS和APEX。 REST内容(特别是RAW数据)中包含下一个分页集的URL。对于第一组数据,此URL参考位于REST数据流的末尾。对于每个后续数据集,URL引用位于原始数据流的开头,因此您必须检查两个位置。这是我正在使用的代码...

function IsMoreRESTDataAvailable(Content: String) : Boolean;
var
Test600 : String;
begin
  // This routine takes the RESTResponse.Content, aka the raw REST data, and checks to see if there is a NEXT: string
  // in either the end of the data (only available for the FIRST DATA set
  // or the beginning of the data

      result := False;

      Test600 := RightStr(Content, 600);
      If AnsiPos('"next":{"$ref":"https://<YOUR_SERVER_HERE>', Test600) <> 0 then
      begin
        result:= True;
        Exit;
      end;

       // If we didn't find it at the end of the REST content, then check at the beginning
       Test600 := LeftStr(Content, 600);
      If AnsiPos('"next":{"$ref":"https://<YOUR_SERVER_HERE>', Test600) <> 0 then
      begin
        result:= True;
        Exit;
      end;

end;