#1 2015-04-27 08:11:06

yankee
Member
Registered: 2015-04-08
Posts: 7

Early binding TSQLTable

Hi,

I used some parts of this beautiful framework to implement a REST client for our custom server (NOT a mORMot Server).
This server exposes some services as JSON structures.
In short, i used
- TWinHTTP to invoke the services
-_JSONFast to parse the response
- TSQLTableJSON.CreateFromTables([TSQLMyResponseContentMappedRecord], '', MyJsonContent)  to map the response to a TSQLTable made of specific record structures.

So, now I have a MyTable: TSQLTableJSON whose rows can be mapped to TSQLMyResponseContentMappedRecord structures:

type
  TSQLMyResponseContentMappedRecord = class(TSQLRecord)
  private
    fMyFirstField: RawUTF8;
    fMySecondField: Integer;
  published
    property MyFirstField: RawUTF8 read fMyFirstField write fMyFirstField;
    property MySecondField: Integer read fMySecondField write fMySecondField;
  end;

I know I can read it this way, with Late Binding:

var
  CurrentRow: Variant;

while MyTable.Step(False, @CurrentRow) do
begin
  ...CurrentRow.MyFirstField...
  ...CurrentRow.MySecondField...
  ...etc...
end;

Is there a way to read the current row with EARLY binding, so that I'm sure that accessing a CurrentRow.WrongField yelds a compile-time error?

Thank you.

Offline

#2 2015-04-27 09:33:57

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

Re: Early binding TSQLTable

You can use TSQLMyResponseContentMappedRecord.CreateAndFillPrepare(const aJSON: RawUTF8) then use a regular "while FillOne do begin...end" block.

Online

#3 2015-04-29 09:23:01

yankee
Member
Registered: 2015-04-08
Posts: 7

Re: Early binding TSQLTable

Thank you, this is exactly what I needed.

Analyzing the code in CreateAndFillPrepare I chose to separate

Create and FillPrepare because I already have the TSQLTableJSON object I used to parse the JSON,
and also because I need that object to have the rowcount.

Or is there a better way to get the RowCount?

Offline

#4 2015-04-29 09:32:09

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

Re: Early binding TSQLTable

Using TSQLTableJSON to get the RowCount is the preferred way, since it is optimized for all flavors of input format (e.g. in non expanded mode, there is an optional "rowCount": field in the input JSON, which speed up the whole process a lot in case of huge resultset).

Online

Board footer

Powered by FluxBB