Delphi FireDAC与ADO读写数据的性能测试


本文整理自网络,侵删。

 
FireDAC,ADO性能测试

以前使用过BDE、ADO、DBX等数据引擎,后来发现它们都没有UNIDAC好用,

所以在很长的一段时间内中间件都使用UNIDAC作为数据引擎。

偶然的机会,使用了DELPHI XE5自带的FIREDAC数据引擎,在开发了几个项目以后

发现它完全可以同UNIDAC相媲美,但UNIDAC购买费用是几万美刀,而FIREDAC是免费的。

 

数据量2w行,字段30个



第一次open



fd读取数据用时363毫秒,ado用时783毫秒



第二次open

fd读取数据用时10毫秒,ado用时553毫秒







遍历所有记录



第一次



fd读取数据用时2438毫秒,ado用时5590毫秒



第二次

fd读取数据用时1988毫秒,ado用时5548毫秒





FireDac 组件说明一
TFDManager连接定义和Connect连接管理
TFDConnection
数据库连接组件,支持三种连接方式:1.持久定义(有一个唯一名称和一个配置文件,可以由FDManager管理)

例:

 

uses
  FireDAC.Comp.Client, FireDAC.Stan.Intf;
var
  oDef: IFDStanConnectionDef;
begin
  oDef := FDManager.ConnectionDefs.AddConnectionDef;
  oDef.Name := 'MSSQL_Connection';
  oDef.DriverID := 'MSSQL';
  oDef.Server := '127.0.0.1';
  oDef.Database := 'Northwind';
  oDef.OSAuthent := True;
  oDef.MarkPersistent;
  oDef.Apply;
  .....................
  FDConnection1.ConnectionDefName := 'MSSQL_Connection';
  FDConnection1.Connected := True;
end;


2.私有定义(有一个唯一名称可以由FDManager管理,无配置文件)

例:

var
  oParams: TStrings;
begin
  oParams := TStringList.Create;
  oParams.Add('Server=127.0.0.1');
  oParams.Add('Database=Northwind');
  oParams.Add('OSAuthent=Yes');
  FDManager.AddConnectionDef('MSSQL_Connection', 'MSSQL', oParams);
  .....................
  FDConnection1.ConnectionDefName := 'MSSQL_Connection';
  FDConnection1.Connected := True;
end;
3.临时定义(没有名称和配置文件,不能由FDManager管理,运行时将参数写入params属性)

例:

uses
  FireDAC.Phys.IBDef, FireDAC.Phys.IBWrapper;
......
FDConnection1.DriverName := 'IB';
with FDConnection1.Params as TFDPhysIBConnectionDefParams do begin
  Protocol := ipTCPIP;
  Server := '127.0.0.1';
  Database := 'c:\IB\employee.gdb';
  UserName := 'sysdba';
  Password := 'masterkey';
end;
FDConnection1.Connected := True;
2. FDConnection1.ConnectionString := 'DriverID=MSSQL;Server=127.0.0.1;Database=Northwind;User_name=sa';
FDConnection1.Connected := True;)

end;

TFDTransaction数据库事务管理
TADCommand执行SQL语句。不返回结果
TFDTableAdapter提供应用程序与数据之间的通信
TFDSchemaAdapter
集中缓存更新。非常重要且实用的组件。先要将数据集,设置CachedUpdates属性为True。

TFDMemTableFireDAC自家的内存表,三层必备的组件,也是非常重要,完全可以替代ClientDataSet
FDQuery类似于ADOQuery的组件,直接SQL语句并存储返回结果
TFDStoredProc执行服务器存储过程
TFDTable类似于ADOTable,数据库表数据集
 

FDUpdateSQL生成添加,删除,修改SQL语句
TFDMetaInfoQuery查询数据源信息
TFDEventAlerter
负责处理数据库事件通知

使用TFDEventAlerter类来处理数据库事件通知。
FDEventAlerter1.Options.Kind := 'DBMS_ALERT';
FDEventAlerter1.Names.Text := 'Customers';
FDEventAlerter1.Options.Synchronize := True;
FDEventAlerter1.Options.Timeout := 10000;
FDEventAlerter1.OnAlter := DoAlert;
FDEventAlerter1.OnTimeout := DoTimeout;
FDEventAlerter1.Active := True;
........
procedure TForm1.DoAlert(ASender: TFDCustomEventAlerter;
  const AEventName: String; const AArgument: Variant);
begin
  if CompareText(AEventName, 'Customers') = 0 then
    qryCustomers.Refresh;
end;
procedure TForm1.DoTimeout(ASender: TObject);
begin
  qryCustomers.Refresh;
end;
TFDLocalSQLSQLite-based本地SQL引擎
TFDGUIxErrorDialog错误对话框
TFDGUIxLoginDialog
登陆对话框

with FDGUIxLoginDialog1.VisibleItems do begin
  Clear;
  Add('Server');
  Add('User_name=Benutzer');
  Add('Password=Kennwort');
  Add('OSAuthent');
end;
FDConnection1.LoginDialog := FDGUIxLoginDialog1;
FDConnection1.Connected := True;
TFDGUIxAsyncExecuteDialog这个对话框显示了SQL查询执行的进展
TFDGUIxScriptDialog这个对话框显示了一个SQL脚本执行进展
TFDGUIxWaitCursor数据库游标控制,这个是强行加到FireDAC应该程序中的
TFDMoniRemoteClientLink使用TFDMoniRemoteClientLink组件链接FDMonitor跟踪功能,应用程序和设置
TFDMSAccessService实现Microsoft Access数据库的创建、删除、压缩和修复服务
TFDScript实现SQL脚本引擎,能够执行一系列SQL查询
TFDBatchMove不同数据源之间的数据转移

来源:http://www.xuexidashi.vip/h-nd-1263.html#_np=125_826

相关阅读 >>

Delphi tstreamwriter tstreamreader 流操作3

Delphi 释放bitmap

Delphi 读取图像文件base64编码加载到image组件显示图片

Delphi xe 的 tdictionary

Delphi 检测文件是否被占用

Delphi 判断表字段是否存在

Delphi如何粘贴html格式文本到windows剪切板

Delphi 读写文本文件

Delphi: ttreeview 中禁止双击事件展开或关闭节点

Delphi 基础学习指定字符替换其他字符

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...