naren
naren

Reputation: 629

Oracle Database Connection in Delphi 5

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.

Upvotes: 2

Views: 6489

Answers (3)

user160694
user160694

Reputation:

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.

Upvotes: 0

Arnaud Bouchez
Arnaud Bouchez

Reputation: 43053

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

Upvotes: 2

RRUZ
RRUZ

Reputation: 136441

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.

Upvotes: 2

Related Questions