Mega Search
23.2 Million


Sign Up

Make a donation  
FireDAC Datasnap REST server - Cannot hide/rename columns fo  
News Group: embarcadero.public.delphi.database.multi-tier

Hello
We have a Delphi XE5 Datasnap REST JSON server build with FireDAC components.

The REST method is implemented like that:
function TSmartCashMethods.GetArticleInfo(aTypeOf, aNrShop: Integer; aValueSearch: String): TDataSet;
begin
....Init variables
  qGetArticolInfo.Close;
.... Parametrisation
  qGetArticolInfo.Open;
  Result := qGetArticolInfo;
end;

 where qGetArticolInfo is a TFDQuery used to select data from a Firebird SQL database.

Due to our bussines logic we also need to use some technical fields returned from the TFDQuery for calculated fields.
We don't want these fields to appear in tha REST JSON result.
And we want to name with an alias the internal database fields for the rest of the fields.
We tryed to hide fields from the Dataset fields editor but they keep appearing on the JSON server response.
We changed the DisplayLabel property for aliased fields but it returns always the original field names on the JSON response.

Can you help us with an ideea for JSON output fields filtering using FireDAC?

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 12-Mar-2014, at 3:33 AM EST
From: Dor-Bujor Padureanu
 
Re: FireDAC Datasnap REST server - Cannot hide/rename column  
News Group: embarcadero.public.delphi.database.multi-tier
Are you able to change the query so that it only returns the fields that you require? Maybe the result set could be calculated by a stored procedure on the Interbase server. (Refer http://edn.embarcadero.com/article/27197)

Steve

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 13-Mar-2014, at 8:29 PM EST
From: Stephen Corbett
 
Re: FireDAC Datasnap REST server - Cannot hide/rename column  
News Group: embarcadero.public.delphi.database.multi-tier
> {quote:title=Stephen Corbett wrote:}{quote}
> Are you able to change the query so that it only returns the fields that you require? Maybe the result set could be calculated by a stored procedure on the Interbase server. (Refer http://edn.embarcadero.com/article/27197)
> 
> Steve

Thank you Steve,

This is not always a solution. Due to some business logic you may have calculated fields at the Dataset level, that cannot be provided to the JSON output.
Hiding unnecessary fields for the JSON output is a filtering issue!
I think this is an problem that should be solved in the future!

Dor

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 14-Mar-2014, at 11:51 AM EST
From: Dor-Bujor Padureanu
 
Re: FireDAC Datasnap REST server - Cannot hide/rename column  
News Group: embarcadero.public.delphi.database.multi-tier
If you are using persistent fields, are then only these fields included into JSON output ?

-- 
With best regards,
Dmitry Arefiev / FireDAC Architect

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 16-Mar-2014, at 10:20 AM EST
From: Dmitry Arefiev
 
Re: FireDAC Datasnap REST server - Cannot hide/rename column  
News Group: embarcadero.public.delphi.database.multi-tier
> {quote:title=Dmitry Arefiev wrote:}{quote}
> If you are using persistent fields, are then only these fields included into JSON output ?
> 
> -- 
> With best regards,
> Dmitry Arefiev / FireDAC Architect

Hello Dmitry
Thank you for your reply!! 

By default we have noticed that ONLY persistent fields, returned directly from SQL, are included into the JSON output.
As I said we also need to provide into the JSON output some calculated fields. These fields are NEVER exported to JSON.

So, in order to have this fields values returned, we "created" fake aliases for the calculated fields inside SELECT statement from the FDQuery SQL: for example: CAST(NULL AS VARCHAR(1)) AS VAT_LETTER.
After that, because the JSON output is based on the order of the fields inside original SQL SELECT clause we moved the calculated field from the Fields Editor, in the corresponding position of the "fake" field inside SQL.
The main issue that remained using the workaround above is that we cannot hide remaining, unnecessary fields for JSON output!!
I think this is just a workaround we found and this is not a good way of doing this. 

The implementation of the JSON method returns a TDataSet.
Example:

function TSmartCashMethods.GetModifiedArticles(): TDataSet;
begin
  qGetArticoleByVersion.Close;
  qGetArticoleByVersion.ParamByName('ALASTVERSION').AsInteger := 1;
  qGetArticoleByVersion.ParamByName('AIDSTORE').AsInteger     := 1;
  qGetArticoleByVersion.Open;
  Result := qGetArticoleByVersion;
end;

Where qGetArticoleByVersion is a TFDQuery.

As a summary the problems with FireDAC TDataSet are:

1. It cannot export calculated fields;
2. You cannot put aliases to the fields using DisplayLabel property as expected (you have to put an alias in AS clause on the SQL statement)
3. You cannot hide fields from the original SQL returned columns for JSON export. We expected to use Visible=False property but it doesn't work!!

Any help would be appreciated!

Regards,
Dor

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 17-Mar-2014, at 4:25 AM EST
From: Dor-Bujor Padureanu