#1 2013-01-14 13:52:51

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Blobfields handling , server side

Hi Ab

I am currently trying to fill a table with data, serverside.

I get access to the "current" rest server using this method:

function TLCSSimulationImpl.GetSQLRest: TSQLRest; // getter for SQLRest property
begin
  if Assigned(ServiceContext.Factory)
    then Result:=ServiceContext.Factory.RestServer
  else Result:=nil;
  if Result=nil then
    raise ELCSSimulationFatal.CreateFmt('%s.GetSQLRest - Restserver not available',[ClassName]);
end;

And I would like to update my blob fields the same way it is accomplished using TSQLRestCLient.UpdateBlobfields, but unfortunately the UpdateBlobFields nor the RetrieveBlobFields methid is implemented in the TSQLRest base class...

  ...
    SQLRest.UpdateBlobFields(Rec);
  ...

Will this be implemented soon, or should I look for a different solution?

regards - hans

Offline

#2 2013-01-14 15:25:20

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Re: Blobfields handling , server side

For intermediate I have created this helper class to get around it. Unfortunately I had to copy GetLongStrProp and GetLongStrProp from mormot.pas into my own unit, as they were not declared in the interface section.

I strongly suggest UpdateBlobFields and RetrieveBlobfields to be added to TSQLRest as virtual (abstract?) methods so they will be available on both server and client side.


type
  TSQLRestBlobHelper=class helper for TSQLRest
  public
    function UpdateBlobFields(Value: TSQLRecord): boolean;
    function RetrieveBlobFields(Value: TSQLRecord): boolean;
  end;

...

function TSQLRestBlobHelper.RetrieveBlobFields(Value: TSQLRecord): boolean;
var BlobData: TSQLRawBlob;
    i: integer;
begin
  result := false;
  if (Self=nil) or (Value=nil) or (Value.ID<=0) then
    exit;
  result := True;
  with Value.RecordProps do
  if BlobFields<>nil then
    for i := 0 to high(BlobFields) do
    begin
      Result:=Result and RetrieveBlob(TSQLRecordClass(Value.Classtype),Value.ID,BlobFields[i].Name,BlobData);
      if Result then
        SetLongStrProp(Value,BlobFields[i].PropInfo,BlobData)
      else Exit;
    end;
  result := true;
end;

function TSQLRestBlobHelper.UpdateBlobFields(Value: TSQLRecord): boolean;
var BlobData: RawByteString;
    i: integer;
begin
  result := false;
  if (Self=nil) or (Value=nil) or (Value.ID<=0) then
    exit;
  result := True;
  with Value.RecordProps do
  if BlobFields<>nil then
    for i := 0 to high(BlobFields) do
    begin
      GetLongStrProp(Value,BlobFields[i].PropInfo,BlobData);
      Result:=Result and UpdateBlob(TSQLRecordClass(Value.Classtype),Value.ID,BlobFields[i].Name,BlobData);
      if not result then
        exit;
    end;
end;

Offline

#3 2013-01-14 16:26:40

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,270
Website

Re: Blobfields handling , server side

Good idea.

Ticket?
wink

Online

#4 2013-01-15 08:11:23

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Re: Blobfields handling , server side

Offline

#5 2013-01-15 14:42:08

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,270
Website

Re: Blobfields handling , server side

It's done for UpdateBlobFields() and RetrieveBlobFields() methods, with optimized overriden implementations
See http://synopse.info/fossil/info/5f90c760e2 and http://synopse.info/fossil/info/6a260c2e19

It was a bit more complicated than you guessed, since I wanted to implement some direct overriden methods, with much more optimized data access (to minimize data conversion or transfert, and use a single SQL request on server side).

Online

#6 2013-01-15 18:43:45

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Re: Blobfields handling , server side

Yay!

Offline

Board footer

Powered by FluxBB