TSQLConnection和TDSRestConnection
两者都可以作为DATASNAP的客户端连接,且都可以自动生成DATASNAP的客户端远程方法代理类。
TSQLConnection既可以作为TCP连接,也可以作为HTTP连接。TDSRestConnection只可以作为HTTP连接。
TSQLConnection是dbexpress其中的一个控件,既可以连数据库,也可以连DATASNAP服务端。
从TDSRestConnection自动的客户端远程方法代理类来看,它也依赖dbexpress。
在没有FIREDAC以前,DELPHI官方的数据库引擎方案是dbexpress,而新的DATASNAP恰是那个时候推出来的(DELPHI2009),不免同dbexpress捆绑得太紧。
以至后来虽然dbexpress在数据库驱动方面已经停更,但DATASNAP却没有清除dbexpress。
TDSRestConnection自动生成的代理类:
TServerMethods1Client = class(TDSAdminRestClient) private FtestCommand: TDSRestCommand; FtestCommand_Cache: TDSRestCommand; public constructor Create(ARestConnection: TDSRestConnection); overload; constructor Create(ARestConnection: TDSRestConnection; AInstanceOwner: Boolean); overload; destructor Destroy; override; function test(params: TMsgPack; const ARequestFilter: string = ''): TMsgPack; function test_Cache(params: TMsgPack; const ARequestFilter: string = ''): IDSRestCachedTMsgPack; end;
TSQLConnection自动生成的代理类:
TServerMethods1Client = class(TDSAdminClient) private FtestCommand: TDBXCommand; public constructor Create(ADBXConnection: TDBXConnection); overload; constructor Create(ADBXConnection: TDBXConnection; AInstanceOwner: Boolean); overload; destructor Destroy; override; function test(params: TMsgPack): TMsgPack; end;
调用:
procedure TForm2.Button1Click(Sender: TObject); begin var send: TMsgPack := TMsgPack.Create; send.Force('table').AsString := 'tunit'; send.Force('sql').AsString := 'select top 1000 * from tunit'; SQLConnection1.Open; var m: unit1.TServerMethods1Client := unit1.TServerMethods1Client.Create(SQLConnection1.DBXConnection); var recv: TMsgPack := m.test(send); ClientDataSet1.Data := recv.Force('data').AsVariant; m.Free; end; procedure TForm2.Button2Click(Sender: TObject); begin var send: TMsgPack := TMsgPack.Create; send.Force('table').AsString := 'tunit'; send.Force('sql').AsString := 'select top 1000 * from tunit'; var m: ClientClassesUnit1.TServerMethods1Client := ClientClassesUnit1.TServerMethods1Client.Create(DSRestConnection1); var recv: TMsgPack := m.test(send); ClientDataSet1.Data := recv.Force('data').AsVariant; m.Free; end;