2
Building OCI Applications
This chapter provides an overview
of how to build Oracle database applications using OCI.
Specific topics discussed are
Writing
OCI Applications
The general goal of an Oracle Call Interface
application is to connect to an Oracle server, engage in data exchange,
and perform necessary data processing. While some flexibility exists in
the order in which specific tasks can be performed, every OCI application
needs to accomplish particular steps.
The basic programming structure used by an OCI application
is as follows:
-
Initialize the OCI programming environment and processes.
-
Allocate necessary handles, and establish a server
connection and a user session.
-
Issue SQL statements to the server, and perform necessary
application data processing.
-
Free statements and handles not to be reused, or reexecute
prepared statements, or prepare a new statement.
-
Terminate user session and server connection.
Compiling
OCI Applications
When you compile an OCI application, you must include the
appropriate OCI header files.
The header files are located in the
\ORACLE_HOME\OCI\INCLUDE
directory.
Linking
OCI Applications
The OCI calls are implemented in dynamic link libraries (DLLs)
that Oracle provides. The DLLs are located in the
\ORACLE_HOME\BIN
directory and are part of the Required Support Files.
To use the Oracle DLLs to make OCI calls, you must link your
application with OCI.LIB
You do not have to indicate any special link options.
Note:
Other libraries may be necessary (such as MSVCRT.LIB for
Microsoft). These depend on your compiler.
|
OCI.LIB
OCI.LIB is a single, programmatic interface to Oracle.
Note:
In the Oracle8 OCI, Oracle has removed any version number
from the library name OCI.LIB.
|
Client
DLL Loading When Using LoadLibrary()
The directories below are searched in the following order
by LoadLibrary:
-
Directory from which the application is loaded
-
Current directory
-
On Windows NT:
-
32-bit Windows system directory (SYSTEM32). Use the
GetWindowsDirectory
function to obtain the path of this directory.
-
16-bit Windows directory (SYSTEM). There is no Windows
API function that obtains the path of this directory, but it is searched.
-
On Windows 95 or Windows 98:
-
Windows directory. Use the GetWindowsDirectory
function to obtain the path of this directory.
-
Directories listed in the PATH environment variable
The Oracle
XA Library
The XA Application Program Interface
(API) is typically used to enable an Oracle8 database to interact with
a transaction processing (TP) monitor, such as:
-
BEA Tuxedo
-
IBM Transarc Encina
-
IBM CICS
You can also use TP monitor statements in your client programs.
The use of the XA API is supported from OCI. The ORAXA8.DLL must be contained
in the execution path of the calling program.
The Oracle XA Library is automatically installed
as part of Oracle8 Enterprise Edition. The following components are created
in your Oracle home directory:
Compiling
and Linking an OCI Program with the Oracle XA Library
To compile and link an OCI program:
-
Compile PROGRAM.C by using Microsoft Visual C++ or
Borland C, making sure to include ORACLE_HOME\RDBMS\XA in your path.
-
Link PROGRAM.OBJ with the following libraries:
-
Run PROGRAM.EXE.
XA Dynamic
Registration
The Oracle8 database supports the use
of XA dynamic registration. XA dynamic registration improves the performance
of applications interfacing with XA-compliant TP monitors. For TP Monitors
to use XA dynamic registration with an Oracle8 database on Windows NT,
you must add either an environmental variable or a registry variable to
the Windows NT computer on which your TP monitor is running. See either
of the following sections for instructions:
After adding this variable, see the Oracle8 Server Application
Developer's Guide for information on using XA dynamic registration.
Adding
an Environmental Variable for the Current Session
Adding an environmental variable at the command prompt affects
only the current MS-DOS session.
To add an environmental variable:
-
From the computer where your TP monitor is installed,
enter the following at the MS-DOS command prompt:
C:\> SET ORA_XA_REG_DLL = VENDOR.DLL
where VENDOR.DLL is the TP monitor DLL
provided by your vendor.
Adding
a Registry Variable for All Sessions
Adding a registry variable affects all
sessions on your Windows NT computer. This is useful for computers where
only one TP monitor is running.
To add a registry variable:
-
Go to the computer where your TP monitor is installed.
-
On Windows NT, enter the following at the MS-DOS command
prompt:
C:\> REGEDT32
On Windows 95/98, enter:
C:\> REGEDIT
The Registry Editor
window appears.
-
Go to HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE.
-
Choose the Add Value option in the Edit menu.
The Add Value dialog box appears.
-
Type ORA_XA_REG_DLL in the Value Name text box.
-
Select REG_EXPAND_SZ from the Data Type list box.
-
Click OK.
The String Editor dialog box appears.
-
Type VENDOR.DLL in the String field, where
VENDOR.DLL
is the TP monitor DLL provided by your vendor.
Click OK.
The Registry Editor adds the parameter.
-
Choose Exit from the Registry menu.
The registry exits.
Running
OCI Applications
To run an OCI application, ensure that
the entire corresponding set of RSFs is installed on the machine that is
running your OCI application.
Using the
Object Type Translator and the INTYPE File
The Object Type Translator (OTT) utility
converts database definitions of object types and named collection types
into C struct declarations which can be included in an OCI or ProC/C++
application. When running the OTT, the INTYPE file informs the OTT which
user-defined types should be translated.
The INTYPE file also controls the naming of the generated
structs. The INTYPE file can be a user-created file, or the outtype file
of a previous invocation of the OTT. If the INTYPE parameter is not used,
all types of the schema to which the OTT connects are translated.
OTT on Windows NT can be invoked from the command line,
as on the Solaris platform. OTT parameters can be specified on the command
line or in a configuration file. Certain parameters can also be specified
in the INTYPE file.
For Windows NT, the default configuration file is
\ORACLE_HOME\PRECOMP\ADMIN\OTT\OTTCFG.CFG.
Additionally, a configuration file may be named on the
command line. For complete information, see the OTT online Help.
Additional
Information
For more information, see the following documents: