Is it possible to modify the TQuery.SQL property when it resides in a remote data module?
Yes. There are three different avenues to accomplish this:
1. If it is a parameterized query, you can use the IProvider.SetParams call. Assuming you have 2 parameters (Param and Param2). The following code fragment demonstrates matching by index, Value goes to the first parameter, etc...
ClientDataSet .Provider.SetParams(VarArrayOf(Value , Value2));
Or matching by param name:
var
V: Variant;
ParamCount: Integer; //used for ease of reading
begin
ClientDataSet .Close;
ParamCount := 2;
V := VarArrayCreate([0, ParamCount - ], varVariant);
V[0] := VarArrayOf(['Param ',Value ]);
V[ ] := VarArrayOf(['Param2',Value2]);
ClientDataSet .Provider.SetParams(V);
ClientDataSet .Open;
end;
For more example code see \demos\midas\setparam.2. If you want to change the SQL, then you can use the IProvider.DataRequest method.
On the Client;
CDS.Data := CDS.Provider.DataRequest('select * from customer');
On the server, you must use a TProvider object, and assign the OnDataRequest event;
function TForm .Provider DataRequest(Sender: TObject;
Input: OleVariant): OleVariant;
begin
//assumes DataSet is a TQuery.
Provider .DataSet.Close;
TQuery(Provider .DataSet).SQL.Text := Input;
Provider .DataSet.Open;
Result := Provider .Data;
end;
For more example code see \demos\midas\adhoc.
3. Create you own interface function that executes the SQL statement.
In the RemoteDataModule:
a. Edit | Add To Interface "procedure ExecSQL(SQL:
WideString);" This will add a procedure to your interface.
b. On the server, code the new procedure:
procedure RemoteData.ExecSQL(SQL: WideString);
begin
{ Query is kept in the RemoteDatamodule for this purpose}
Query .SQL.Text := SQL;
Query .ExecSQL;
end;
c. On the client, call the new procedure:
RemoteServer .AppServer.ExecSQL('Delete from deal details where dealnumber= ');