#1 2011-12-07 13:02:32

Sir Rufo
Member
Registered: 2011-10-14
Posts: 24

TSQLRest.Retrieve and the InternalState

The InternalState Property is only filled with data in TSQLRestClientURI.Retrieve
All other Methods declared in TSQLRest did not fill the Property - but they can fill wink

I just made the changes to TSQLRest.Retrieve(const SQLWhere: RawUTF8; Value: TSQLRecord)

function TSQLRest.Retrieve(const SQLWhere: RawUTF8; Value: TSQLRecord): boolean;
var T: TSQLTable;
begin
  if (self=nil) or (Value=nil) then
    T := nil else
    T := InternalListJSON(Value.RecordClass,Value.RecordProps.
      SQLFromSelectWhere('*',SQLWhere+' LIMIT 1'));
  if T=nil then
    result := false else
    try
      if T.RowCount>=1 then begin
        Value.FillFrom(T,1); // fetch data from first result row
        Value.fInternalState := T.InternalState; // the missing row in here
        result := true;
      end else
        result := false;
    finally
      T.Free;
    end;
end;

It's very useful to check the InternalState of the Record against the ServerInternalState, to decide if there are possible changes on the Server.

EDIT
This Method is the only one which did not fill the InternalState of the Record smile

Last edited by Sir Rufo (2011-12-07 13:14:37)

Offline

#2 2011-12-07 16:07:35

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

Re: TSQLRest.Retrieve and the InternalState

Nice catch.

I preferred to change TSQLRecord.FillFrom() method, but the fix is very similar.

See http://synopse.info/fossil/info/4d8613523e

Thanks!

I'd like to a tuned per-class or per-instance caching at both Client and Server side.
This would ensure another level of performance tuning for mORMot-based applications.

add a generic per-TSQLRecordClass or per-TSQLRecord caching, at TSQLRest level (with timeout and RESTful safety) - this may be used on both Client and Server side for speed enhancement of immutable objects (like configuration);

See http://synopse.info/fossil/wiki?name=RoadMap

Offline

#3 2017-06-19 13:42:09

ASiwon
Member
From: Poland
Registered: 2015-01-30
Posts: 82

Re: TSQLRest.Retrieve and the InternalState

Hi,

is it possible to add filling InternalState property for RetrieveList* methods? Especially in generics version it would be very usefull for me. It could be done in TSQLTable.ToObjectList<T>

function TSQLTable.ToObjectList<T>: TObjectList<T>;
var R,Item: TSQLRecord;
    Row: PPUtf8Char;
    i: integer;
begin
  result := TObjectList<T>.Create; // TObjectList<T> will free each T instance
  if (self=nil) or (fRowCount=0) then
    exit;
  R := TSQLRecordClass(T).Create;
  try
    R.FillPrepare(self);
    Row := @fResults[FieldCount];     // Row^ points to first row of data
    {$ifdef ISDELPHIXE3}
    result.Count := fRowCount;         // faster than manual Add()
    for i := 0 to fRowCount-1 do begin
      Item := TSQLRecordClass(T).Create;
      PPointerArray(result.List)[i] := Item;
    {$else}
    for i := 0 to fRowCount-1 do begin
      Item := TSQLRecordClass(T).Create;
      Result.Add(Item);
    {$endif}
      R.fFill.Fill(pointer(Row),Item);
      Item.fInternalState := Self.InternalState;   // Filling InternalState property
      Inc(Row,FieldCount); // next data row
    end;
  finally
    R.Free;
  end;
end;

If it is impossible to change TSQLTable.ToObjectList function it could be done in TSQLRest.RetrieveList<T>. In this case function should be changed to:

function TSQLRest.RetrieveList<T>(const FormatSQLWhere: RawUTF8;
  const BoundsSQLWhere: array of const; const aCustomFieldsCSV: RawUTF8): TObjectList<T>;
var Table: TSQLTable;
  i: Integer;
begin
  result := nil;
  if self=nil then
    exit;
  Table := MultiFieldValues(TSQLRecordClass(T),aCustomFieldsCSV,FormatSQLWhere,BoundsSQLWhere);
  if Table<>nil then
  try
    result := Table.ToObjectList<T>;
      // filling InternalState property
    for i := 0 to result.Count - 1 do
      result[i].fInternalState := Table.InternalState;
  finally
    Table.Free;
  end;
end;

Last edited by ASiwon (2017-06-19 21:27:08)


best regards
Adam Siwon

Offline

#4 2017-06-21 12:52:02

ASiwon
Member
From: Poland
Registered: 2015-01-30
Posts: 82

Re: TSQLRest.Retrieve and the InternalState

Hi,

I have add a pull request for this issue: https://github.com/synopse/mORMot/pull/43
Please add this correction to the mORMot source code.


best regards
Adam Siwon

Offline

Board footer

Powered by FluxBB