Delphi 5 中的 Oracle 数据库连接

发布于 2024-11-19 23:20:40 字数 96 浏览 4 评论 0原文

我使用的是 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尘世孤行 2024-11-26 23:20:40

TDatabase 组件是 BDE(Borland 数据库引擎),这是一个已弃用的技术,请尝试使用其他支持 Oracle 的替代方案,例如 ADO 或 Zeos。有关 ADO 的介绍,请查看 Embarcadero 文档。 使用 ADO 组件,如果您选择 Zeos,请选中 < a href="http://zeos.firmos.at/viewforum.php?f=3" rel="nofollow">官方文档。

The TDatabase component is part of the BDE (Borland Database Engine), which is a deprecated technology, instead try using another alternatives which supports Oracle like ADO or Zeos. For an introduction to ADO check the Embarcadero Docs. Working with ADO Components and if you choose Zeos check the Official documentation.

冬天旳寂寞 2024-11-26 23:20:40

很有趣,我刚刚完成(几分钟前)我的开源原生 Oracle 的移植访问 Delphi 5。

以下是该单元的主要功能:

  • 直接访问 Oracle Call Interface (OCI) 客户端,无需 BDE、Midas、DBExpress、OleDB 或 ODBC 提供程序;
  • 专用于从修订版 8 开始的任何版本的 Oracle OCI 接口;
  • 针对 Oracle 11g 的最新功能进行了优化(例如,使用本机 Int64 检索不带小数的 NUMBER 字段);
  • 能够与 Oracle Instant Client 配合使用,无需安装应用程序;
  • 原生 Unicode(使用内部 UTF-8 编码),适用于所有版本的 Delphi,对每个数据库字符集进行特殊处理;
  • 尝试在每个版本的 Oracle 客户端中实现最佳性能;
  • 设计用于在任何版本的 Windows 下运行,无论是 32 位还是 64 位架构;
  • 使用新的专用 Variant 类型(类似于 Ole Automation 运行时属性)对列名称进行后期绑定访问;
  • 连接是多线程就绪的,内存和 CPU 资源开销较低;
  • 可以使用“//host[:port]/[service_name]”等连接字符串,避免使用 TNSNAME.ORA 文件;
  • 使用行数组和 BLOB 获取,以获得最佳性能(例如,ZEOS/ZDBC 没有处理此问题);
  • TQuery 模拟类,用于直接重用现有代码,替代 BDE;
  • 处理准备好的语句 - 但默认情况下,我们依赖 OCI 端语句缓存(如果可用);
  • 本机导出到 JSON 方法,这将是我们 mORMot 框架的主要入口点;
  • 兼容 Delphi 5 至 XE;
  • 由于它不使用 DB 单元,也不使用 DBExpress 或此类其他技术,因此可以与任何版本的 Delphi(甚至 Delphi XE Stater 或 Delphi 7 Personal)配合使用;
  • 开源,根据 MPL/GPL/LGPL 许可证发布。

有关更多详细信息,请参阅此网站和反馈

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

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

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 及更高版本允许这样做:

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 方法中使用 DB 组件,请查看 < a href="http://www.terry.net/pages.php?id=549" rel="nofollow">Torry页面中的相应页面:

  • ATOM Access To Oracle Magic;
  • 用于直接 Oracle 访问的 DOCI 组件;
  • 数控OCI8;
  • 橙色组件集;
  • Vlad Karpov 到 Oracle 的本地链接。

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

当然,也有一些非常好的商业组件,仍然可以与 Delphi 5 一起使用。但是您必须付出高昂的代价...顺便说一句,最好升级到较新的 Delphi 版本。 ;)

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:

  • 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 Delphi, 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.

See this web site for more details and feedback.

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;

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;

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 Access To Oracle Magic;
  • DOCI Components for Direct Oracle Access;
  • NC OCI8;
  • Orange Component Set;
  • Vlad Karpov Native Link to 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.

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. ;)

陌伤浅笑 2024-11-26 23:20:40

如果您有 Delphi 5 企业版,您可以使用 BDE 和 Oracle SQL Link 连接到 Oracle。这是从 D5 使用 Oracle 的最快方法。如果您有专业版,则可以通过 ODBC 使用 BDE 使用 Oracle。企业版也应该已经有 ADO 组件,但在我的测试中,它是一个比 SQL 链接差的解决方案,尽管如果您必须稍后移植到较新的 Delphi 版本,它仍然受支持,而 BDE 和 SQL 链接是不是。

帮助和手册中详细介绍了连接步骤。

If you have the Enterprise version of Delphi 5 you can connecto to Oracle using the BDE and the Oracle SQL Link. That's the fastest way to use Oracle from D5. If you have the Professional version, you can use Oracle using the BDE through ODBC. The Enterprise version also should already have the ADO components, but in my tests then it was an inferior solution to the SQL Links, although if you have to port later to a newer Delphi release it is still supported while the BDE and the SQL Links are not.

The steps to connect are detailed in the help and the manuals.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文