Delphi 5中的Oracle数据库连接 [英] Oracle Database Connection in Delphi 5

查看:118
本文介绍了Delphi 5中的Oracle数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Delphi 5版本,并且想连接到Oracle数据库.我有TDatabase组件. 我对如何通过Delphi连接到数据库一无所知.请提供连接数据库的步骤.谢谢.

I am using Delphi 5 version and I want to connect to Oracle Database. I am having TDatabase component. I don't have any idea about how to connect to database through Delphi. Please provide the steps to connect database. thanks.

推荐答案

这很有趣,我刚刚完成(几分钟前)我的开放源Oracle本机Oracle访问Delphi 5的端口.

That's funny, I've just finished (some minutes ago) the port of my Open Source native Oracle access to Delphi 5.

以下是本机的主要功能:

Here are the main features of this unit:

  • 直接访问Oracle调用接口(OCI)客户端,而无需BDE,Midas,DBExpress或OleDB或ODBC提供程序;
  • 从版本8开始,专用于任何版本的Oracle OCI接口;
  • 针对Oracle 11g的最新功能进行了优化(例如使用本机Int64检索不带小数的NUMBER个字段);
  • 能够与Oracle Instant Client一起使用而无需安装程序;
  • Delphi的所有版本的本地Unicode(使用内部UTF-8编码),并对每个数据库字符集进行特殊处理;
  • 试图从每个版本的Oracle客户端中获得最佳性能;
  • 旨在在32位或64位体系结构的任何Windows版本下工作;
  • 使用新的专用Variant类型(类似于Ole Automation运行时属性)对列名称进行后期绑定访问;
  • 连接是多线程就绪的,具有较低的内存和CPU资源开销;
  • 可以使用诸如'//host [:port]/[service_name]'之类的连接字符串,避免使用TNSNAME.ORA文件;
  • 使用Rows Array和BLOB抓取来获得最佳性能(例如,ZEOS/ZDBC不能处理此问题);
  • TQuery仿真类,用于与现有代码直接重用,以代替BDE;
  • 处理预备语句-但是默认情况下,我们依赖OCI侧语句缓存(如果有);
  • 本地导出到JSON方法,这将成为我们mORMot框架的主要切入点;
  • 与直至XE的Delphi 5兼容;
  • 由于它不使用DB单元,也不使用DBExpress或其他技术,因此可以与任何版本的Delphi(甚至是Delphi XE Stater或Delphi 7 Personal)一起使用;
  • 开放源代码,根据MPL/GPL/LGPL许可发布.
  • Direct access to the Oracle Call Interface (OCI) client, with no BDE, Midas, DBExpress, nor OleDB or ODBC provider necessary;
  • Dedicated to work with any version of the Oracle OCI interface, starting from revision 8;
  • Optimized for the latest features of Oracle 11g (e.g. using native Int64 for retrieving NUMBER fields with no decimal);
  • Able to work with the Oracle Instant Client for No Setup applications;
  • Natively Unicode (uses internal UTF-8 encoding), for all version of Delp with special handling of each database char-set;
  • Tried to achieve best performance available from every version of the Oracle client;
  • Designed to work under any version of Windows, either in 32 or 64 bit architecture;
  • Late-binding access to column names, using a new dedicated Variant type (similar to Ole Automation runtime properties);
  • Connections are multi-thread ready with low memory and CPU resource overhead;
  • Can use connection strings like '//host[:port]/[service_name]', avoiding use of the TNSNAME.ORA file;
  • Use Rows Array and BLOB fetching, for best performance (ZEOS/ZDBC did not handle this, for instance);
  • TQuery emulation class, for direct re-use with existing code, in replacement to the BDE;
  • Handle Prepared Statements - but by default, we rely on OCI-side statement cache, if available;
  • Native export to JSON methods, which will be the main entry point for our mORMot framework;
  • Compatible with Delphi 5 up to XE;
  • Since it doesn't use the DB unit, nor DBExpress or such other technologies, works with any edition of Delphi (even Delphi XE Stater or Delphi 7 Personal);
  • Open Source, released under a MPL/GPL/LGPL license.

请参见此网站了解更多详细信息和反馈.

您有一个TQuery包装器,可以像使用BDE一样编写代码.

You have a TQuery like wrapper, to write code just like with the BDE.

或者您也可以这样编写代码:

Or you can write code as such:

procedure Test(Props: TOleDBConnectionProperties; const aName: RawUTF8);
var I: ISQLDBRows;
begin
  I := Props.Execute('select * from Domain.Customers where Name=?',[aName]);
  while I.Step do
    writeln(I['Name'],' ',I.['FirstName'],' ',I['Address']);
end;

var Props: TOleDBConnectionProperties;
begin
  Props := TSQLDBOracleConnectionProperties.Create(
    'TnsName','UserName','Password',CODEPAGE_US);
  try
    Test(Props,'Smith');
  finally
    Props.Free;
  end;
end;

不幸的是,Delphi 5不允许通过变体进行后期绑定,而Delphi 6及更高版本则允许这种变体:

Unfortunately, Delphi 5 do not allow late-binding via a variant, which is allowed with Delphi 6 and up:

procedure Test(Props: TOleDBConnectionProperties; const aName: RawUTF8);
var I: ISQLDBRows;
    Customer: Variant;
begin
  I := Props.Execute('select * from Domain.Customers where Name=?',[aName],@Customer);
  while I.Step do
    writeln(Customer.Name,' ',Customer.FirstName,' ',Customer.Address);
end;

如果您真的想在RAD方法中使用数据库组件,请查看托里页面中的相应页面:

If you really want to use the DB components in a RAD approach, take a look at the corresponding page in Torry's page:

  • ATOM对Oracle Magic的访问;
  • 用于直接Oracle访问的DOCI组件;
  • NC OCI8;
  • 橙色组件集;
  • Vlad Karpov与Oracle的本机链接.

您会找到一些旧的免费组件,这些组件大多数是在Oracle 8时创建的(SynDBOracle针对Oracle 11g进行了优化,但可以与早期版本的Oracle一起使用),但是它们可能更适合您在没有BDE的情况下对Oracle连接的需求.

You'll find there some old free components, mostly created at Oracle 8 time (SynDBOracle is optimized for Oracle 11g but will work with earlier versions of Oracle), but which may better suit your need for Oracle connection without the BDE.

当然,周围也有一些非常好的商业组件,它们仍可与Delphi 5一起使用.但是,您将不得不付出高昂的代价……而且,顺便说一句,最好将其升级到较新的Delphi版本. ;)

Of course, there are also some very good commercial components around, still working with Delphi 5. But you'll have to pay the high price... and should better upgrade to a newer Delphi version, by the way. ;)

这篇关于Delphi 5中的Oracle数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆