Extra parameters

Hi,

Is it possible to pass extra parameters from the client to the server?
These parameters are not present in the SQL-statement at server-side.

For example:
ClientDataModule.tbl_users.Close;
ClientDataModule.tbl_users.Params.Add(‘COMPANY_ID’, ‘TPI’, TDADataType.datString);
ClientDataModule.tbl_users.Params.Add(‘COMPUTER_NAME’, ‘EXTUSR01’, TDADataType.datString);
ClientDataModule.tbl_users.Open;

Freddy

Hi,

your code will work - parameters will be transferred to server, but what you want to reach?
if you want to use them in where, better to use DynamicWhere.
read the DynamicWhere article for details

Hi,

your code will work - parameters will be transferred to server,
No, the server throws an exception ‘Cannot find item ‘…’ in collection of type TDAParamCollection’.

I want to send extra information along with the datarequest.

I want to extract this information in the TDataAbstractService.BeforeGetDatasetData event

Freddy

Hi,

you can get your parameters in the OnValidateDatasetAccess event , but it will fail later at assigning parameter values at

  for i := 0 to High(ParamValues) do
    Result.ParamByName(ParamNames[i]).Value := ParamValues[i];

because your parameters aren’t found in actual dataset


as a workaround, you can override

    function GetData(const aTableNameArray: DataAbstract4_Intf.StringArray;
                     const aTableRequestInfoArray: DataAbstract4_Intf.TableRequestInfoArray): Binary; virtual;

and extract and reset parameters inside aTableRequestInfoArray[x].Parameters array

Hi Evgeny,

I tried the following and at first instance it seems to work:

procedure TDataService.DataAbstractServiceValidateDatasetAccess(Sender: TObject; const aConnection: IDAConnection;
const aDatasetName: string; const aParamNames: array of string; const aParamValues: array of Variant; aSchema: TDASchema;
var Allowed: Boolean);
var
i: integer;
DataSet: TDADataSet;
begin
DataSet := Schema.FindDataset(aDatasetName);

for i := Low(aParamNames) to High(aParamNames) do
begin
DataSet.Params.Add(aParamNames[i], aParamValues[i], TDADataType.datUnknown);
end;
end;

Freddy

Hi,

if you manually add parameters to schema, it will work as expected