TSQLConnection和TDSRestConnection

TSQLConnection和TDSRestConnection

两者都可以作为DATASNAP的客户端连接,且都可以自动生成DATASNAP的客户端远程方法代理类。

TSQLConnection既可以作为TCP连接,也可以作为HTTP连接。TDSRestConnection只可以作为HTTP连接。

TSQLConnection是dbexpress其中的一个控件,既可以连数据库,也可以连DATASNAP服务端。

从TDSRestConnection自动的客户端远程方法代理类来看,它也依赖dbexpress。

在没有FIREDAC以前,DELPHI官方的数据库引擎方案是dbexpress,而新的DATASNAP恰是那个时候推出来的(DELPHI2009),不免同dbexpress捆绑得太紧。

以至后来虽然dbexpress在数据库驱动方面已经停更,但DATASNAP却没有清除dbexpress。

TDSRestConnection自动生成的代理类:

1
2
3
4
5
6
7
8
9
10
11
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自动生成的代理类:

1
2
3
4
5
6
7
8
9
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;

  调用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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;

  

 

 

posted @   delphi中间件  阅读(865)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2019-12-18 MORMOT REST文件上传
2018-12-18 Delphi XE中String、ANSIString、TBytes之间的转换
2018-12-18 论DELPHI三层的数据序列格式的变化
2018-12-18 MORMOT的数据序列
2017-12-18 TSynAuthentication SESSION验证
2017-12-18 生成SESSIONID
2017-12-18 http session
点击右上角即可分享
微信分享提示