Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 Modifying application server SQL from the client.


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= ');

     


  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use