A precompiler is a tool that allows programmers to embed SQL statements in
high-level source programs like C, C++, COBOL, etc. The precompiler accepts
the source program as input, translates the embedded SQL statements into
standard Oracle runtime library calls, and generates a modified source program
that one can compile, link, and execute in the usual way.
Examples are the Pro*C Precompiler for C, Pro*Cobol for Cobol, SQLJ for Java
etc.
The Oracle OCI (Oracle Call Interface), is an alternate low-level interface to the Oracle database.
The SQL precompilers for the various host languages (Pro*C, Pro*Ada, Pro*Fortran,
Pro*COBOL, etc.) reads EXEC SQL commands and generate data structures and
calls to its runtime library: SQLLIB (libsql.a in UNIX). SQLLIB, in turn,
calls the User Program Interface (UPI) to communicate with the database.
It does not generate calls to the Oracle Call Interface (OCI) but you can
mix OCI and Precompiler calls.
For more info about the Oracle Call Interfaces, see the OCI FAQ.
Try to make the switch to version 2.0 as soon as possible. Starting with Oracle7 release 7.3, it will
be the only version available. The support matrix:
Database Version:
Pro*C Version:
7.0
1.5
7.1
1.6 and 2.0
7.2
1.6 and 2.1
7.3
2.2
8.x
8.x
Because Pro*C 2.x behaves differently from Pro*C 1.x, and to ease migration,
both versions of Pro*C were shipped with 7.1 and 7.2. I recommend using 2.x
or higher for any new development. You can use the PARSE=PARTIAL or
PARSE=NONE options to get behavior similar to version 1.x.
The following syntax is used to precompile a Pro*C program:
proc iname=myprog.pc host=C
Oracle includes some sample precompiler programs with it's installation. These
are normally located under the $ORACLE_HOME/precomp/demo/proc (or related) directories.
After you've precompiled your program, invoke the standard host language compiler and linker.
Also remember, if you modify your source code, change the original precompiled source program.
In C, for example, you would modify the *.PC file and not the *.C file. The *.C file gets
overwritten every time you precompile your program.
Look at the following table for other host languages:
You can study the sample makefile provided by Oracle and construct your own,
but it would probably be better to just use "make" to precompile and then
compile your program in one step. Look at this Unix examples:
Oracle7:
make -f $ORACLE_HOME/precomp/demo/proc/proc.mk build EXE=myprog OBJS=myprog.o
Oracle8:
make -f $ORACLE_HOME/precomp/demo/proc/demo_proc.mk build EXE=myprog OBJS=myprog.o
Is there some way to tell the Pro*C preprocessor to search other
directories for include (*.h) files, similar to the C compiler switch
"-I"? I am hoping to avoid having to change all of my
#include statements...
As documented in the Pro*C manual (in the chapter called "Running the
Precompiler") there is an INCLUDE flag that can be used for this. Look at this example:
Indicator variables are used to explicitly handle NULL values.
When you SELECT or FETCH a NULL value into a host variable/array an "ORA-01405: fetched column values is NULL" run-time error will result.
This behaviour was introduced with Oracle7 when you recompiled your programs with the DBMS=V7 (the default) precompiler option.
One workaround for this is to use the NVL() function to prevent the selection of NULL values.
Example:
EXEC SQL SELECT ENAME, SAL, COMM
INTO :emp_name, :emp_sal, :emp_comm:comm_indicator
FROM emp;
if (comm_indicator == -1)
pay = emp_sal;
else
pay = emp_sal + emp_comm;