#1 2012-12-14 14:55:35

corchi72
Member
Registered: 2010-12-10
Posts: 232

Can I send as a parameter TSQLRecordClass in procedure CallBackGetRes

I want to send as a parameter TSQLRecordClass, I know I can run on the server to retrive the correct table. (This function will be executed from multiple tables)
procedures in my server side is

procedure TFileServer.DataFromID(var Ctxt: TSQLRestServerCallBackParams);
var //aData: TSQLRawBlob;
   sfilename:RawUTF8;
   Id:Integer;
   RecordClass: TSQLRecordClass;
   AObject:TSQLObject;
begin
 sfilename :='';
  if not UrlDecodeNeedParameters(Ctxt.Parameters,'ID') then begin
     Ctxt.Error('Missing Parameter');;
   {$ifNdef SERVICE}
    writeln('invalid Request');
    {$ENDIF}
    exit;
  end;

  while Ctxt.Parameters<>nil do begin
    UrlDecodeInteger(Ctxt.Parameters,'ID=',Id,@Ctxt.Parameters);
    UrlDecode(Ctxt.Parameters,'RECORDCLASS=',RecordClass,@Ctxt.Parameters);
  end;

  AObject := TSQLObject(RecordClass.Create);

  if Self.Retrieve(id,AObject,false) then 
  begin
      sfilename := AObject.filename;
      Ctxt.Results([sfilename]);
  end
  else
   begin
    Ctxt.Error('invalid Request');
    exit; // we need a valid record and its ID
   end;

  

end;

Offline

#2 2012-12-14 15:04:37

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

Re: Can I send as a parameter TSQLRecordClass in procedure CallBackGetRes

You should better use the RESTful URI parameters, already existing in Ctxt.

See TSQLRestServerCallBackParams.Table and TSQLRestServerCallBackParams.ID parameters on the server side, and the normal URI encoded as REST, via Table and ID parameters of TSQLRestClientURI.CallBackGet()/CallBackGetResult() methods.
The documentation states it.

Offline

#3 2012-12-14 16:15:56

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: Can I send as a parameter TSQLRecordClass in procedure CallBackGetRes

sorry for the delay in answering, but before I tried if it worked. and it works

..
   
     // - use TSQLRest.Retrieve(Reference) to get a record value

     AObject := TSQLObject(self.Retrieve(RecordReference(Model,Ctxt.Table,Ctxt.ID)));
     Ctxt.Results([(AObject.filename]);
   
 ...

thanks

Offline

#4 2012-12-14 16:40:14

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

Re: Can I send as a parameter TSQLRecordClass in procedure CallBackGetRes

Don't forget to release the TSQLRest.Retrieve(Reference) instance, otherwise you will leak memory.

Using a Reference value will work here, but I suspect the more native could be to work at RESTful URI level, using:
- TSQLRestClientURI.CallBackGet()/CallBackGetResult() methods for client;
- TSQLRestServerCallBackParams.Table and TSQLRestServerCallBackParams.ID parameters on the server side.

Offline

#5 2012-12-17 10:29:01

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: Can I send as a parameter TSQLRecordClass in procedure CallBackGetRes

ok thanks

Offline

Board footer

Powered by FluxBB