English 中文(简体)
在数据分析客户中执行动态图表
原标题:execute dynamic sql in datasnap client

是否可能在数据元件服务器和客户之间分享数据库链接?

我希望在客户中执行动态的q,并取得成果。

最佳回答

I found 2 ways to execute dynamic sql in client side

(1) 使用DbxConnection(dbExpress)

// Server code
function TServerMethods1.GetConnection: TDbxConnection;
begin
  Result := DBConnection.DBXConnection;
end;


//Client code
dbxConnection := ServerMethods.GetConnection;
command := dbxConnection.CreateCommand;
command.Text :=  SELECT COUNT(1) FROM clients WHERE name LIKE :name ;
param := com.CreateParameter;
param.Name :=  name ;
param.DataType := TDBXDataTypes.WideStringType;
param.Value.SetString( %name% );
command.Parameters.AddParameter(param);
reader := command.ExecuteQuery;
reader.Next; // to Fetch row
ShowMessage(reader.Value[0].AsString);

2) 利用Set后裔

www.un.org/spanish/ecosoc 服务器部件

服务器梯度班必须是TDSServer Module后代

  • TConnection descendant
  • TQuery descendant
  • TDataSetProvider (set poAllowCommanedText to true)

www.un.org/spanish/ecosoc 客户部分

  • TSqlConnection (for DataSnap connection)
  • TDsProviderConnection (for DataSnap server methods)
  • TClientDataSet (set provider)

D. 执行询问守则

CDS.Close; // TClientDataSet
CDS.CommandText :=  SELECT COUNT(*) FROM clients WHERE name LIKE :name ;
CDS.Params.ParamByName( name ).AsString :=  %name% ;
CDS.Open;
ShowMessage(CDS.Fields[0].AsString);

www.un.org/spanish/ecosoc 服务器边代码:

MainMethods.pas

TMainMethods = class(TDSServerModule)
  PgQuery: TPgQuery;
  PgQueryProvider: TDataSetProvider;
  PgConnection: TPgConnection;
end;

MainMethods.dfm

object MainMethods: TMainMethods
  Height = 248
  Width = 440
  object PgConnection: TPgConnection
    Left = 200
    Top = 32
    ...
  end
  object PgQuery: TPgQuery
    Connection: PgConnection
    Left = 32
    Top = 24
  end
  object PgQueryProvider: TDataSetProvider
    DataSet = PgQuery
    Options = [poAllowCommandText, poUseQuoteChar]
    Left = 120
    Top = 24
  end
end

www.un.org/spanish/ecosoc 客户代码:

客户。

TVerusClient = class(TDataModule)
  dbxVerusConnection: TSQLConnection;
  dbxSqlConnectionProvider: TDSProviderConnection;
  cdsSqlDataSet: TClientDataSet;
end;

客户dfm

object VerusClient: TVerusClient
  Height = 271
  Width = 415
  object dbxVerusConnection: TSQLConnection
    DriverName =  DataSnap 
    LoginPrompt = False
    ...
  end
  object dbxSqlConnectionProvider: TDSProviderConnection
    ServerClassName =  TMainMethods 
    SQLConnection = dbxVerusConnection
    Left = 176
    Top = 32
  end
  object cdsSqlDataSet: TClientDataSet
    ProviderName =  PgQueryProvider 
    RemoteServer = dbxSqlConnectionProvider
    Left = 176
    Top = 104
  end
end
问题回答

数据Snap(Multi-Tier)申请的主要目标是安全。 你们不能以遥远的方式直接分享物体(连接、资源),但你可以改变会议数据集。

// Server Code
procedure TMyServerMethod.ChangeSQL(ASQL:string); // insecure
begin
  AdoQuery1.Active:=false;
  AdoQuery1.SQL.Text:=ASQL; // AdoQuery,DbxExpress,UniDAC,AnyDac,...    
  AdoQuery1.Active:=true;
end;

使用

// Client Code
procedure TForm1.Button1Click(Sender:TObject);
begin
  Proxy.ChangeSQL( select * from custom_table );// but it is insecure
  // loading remote datasets
end;




相关问题
Delphi 2010 Datasnap - Design Query

I am investigating moving a thick client SQL based Delphi application to Multi Tier thin clients, and have been looking at using Datasnap in Delphi 2010. I have worked through the White Paper written ...

Programs built on Datasnap

I have done a search on Google for applications writen with Datasnap and didn t find much information. What well know applications are written in Datasnap 2009 / 2010 ? Is using Datasnap 2010 a ...

"How to" for DataSnap Filters Compendium

I m trying to use Daniele Teti s Datasnap Filters Compendiun (the cipher ones) without success. Someone have a how to for cipher filters for Datasnap? Regards.

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

热门标签