中国程序员联盟 正在重新改版中ing 不便之处还请见谅 改版后将内容涉及java delphi .net php
 
  首页 | 数据库开发 | 网络通讯 | 多线程 | 多媒体开发 | 图像处理 | 程序人生 | 系统函数 | 控件开发 | Web服务
 
  当前位置:笨鱼delphi技术网>数据库开发>代码分析>文章内容

delphi 在客户端改变服务端查询

来源:站内 关于:bill 发布时间:2007-06-22   [收藏] [推荐]

1. If it is a parameterized query, you can use the
IProvider.SetParams call.  Assuming you have 2 parameters
(Param1 and Param2).  The following code fragment
demonstrates matching by index, Value1 goes to the first
parameter, etc...

ClientDataSet1.Provider.SetParams(VarArrayOf(Value1, Value2));

Or matching by param name:

  
var
  V: Variant;
  ParamCount: Integer;
//used for ease of reading
begin
  ClientDataSet1.Close;
  ParamCount := 2;
  V := VarArrayCreate([0, ParamCount - 1], varVariant);
  V[0] := VarArrayOf(['Param1',Value1]);
  V[1] := VarArrayOf(['Param2',Value2]);
  ClientDataSet1.Provider.SetParams(V);
  ClientDataSet1.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 TForm1.Provider1DataRequest(Sender: TObject;
 Input: OleVariant): OleVariant;
begin
 
//assumes DataSet is a TQuery.
  Provider1.DataSet.Close;
  TQuery(Provider1.DataSet).SQL.Text := Input;
  Provider1.DataSet.Open;
  Result := Provider1.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
{ Query1 is kept in the RemoteDatamodule for this purpose}
  Query1.SQL.Text := SQL;
  Query1.ExecSQL;
end;
  

c. On the client, call the new procedure:
  
RemoteServer1.AppServer.ExecSQL('Delete from deal details
   where dealnumber=1');


[浏览: 次]   
上一篇:delphi MIDAS 中动态强制约束编程   下一篇:delphi MIDAS——多层分布式应用程序服务器
[收藏] [推荐] [返回顶部] [打印本页] [关闭窗口]  
    评论加载中…
google adsense热点文章
·delphi Delphi_动态数组介绍----Delphi
·delphi 检查IP地址
·delphi DBExpress 提高
·delphi 复制Excel列到二维数组
·delphi Delphi_VCL消息处理机制的内幕
·delphi 产生不重复的随机数
·delphi 如何在DELPHI里调用MS office
·delphi 缓冲池
·delphi Asta多层应用实现
·delphi MIDAS——多层分布式应用程序服
·delphi 在WORD文档里添加页签
·delphi Datamodule的应用方式
     delphi技术网 | firefox 下载 | Avant Browser下载 | dedecms 技术网 | drupal 爱好者 | php 技术网
  Copyright@www.delphichm.com,2006-2009.All Rights Reserved.
 
程序员联盟 | delphi Java .net|QQ:707102932