Oracle Precompiler FAQ

What is a precompiler and what is it good for?
A precompiler is a tool that allows programmers to embed SQL statements in a high-level source program. 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 you can compile, link, and execute in the usual way. examples are Pro*C Precompiler for C, Pro*Cobol for Cobol and SQLJ for Java etc.
Back to top of file


What languages are supported?
The following 3GL languages are supported by the Oracle precompilers:
Host Language: File Extention:

Pro* COBOL *.PCO
Pro* Ada *.PAD
Pro* Fortran *.PFO
Pro* C (C++ included) *.PC
Pro* PL/I *.PPL
Pro* Pascal *.PPA
Please note that Oracle8 does not support Pascal, PL/I and Ada. For Java related issues, visit the JDBC/JSQL FAQ.
Back to top of file


What is the difference between OCI and the Precompilers?
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.
Back to top of file


Should I use Pro*C V1 or V2?
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.
Back to top of file


How does one compile a precompiler program?
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:
Language: Program: Precompiler: Precompiled to:

C *.pc proc *.c
COBOL *.pco procob *.cob
FORTRAN *.pfo profor *.for
PASCAL *.ppa propas *.pas
ADA *.pad proada *.ada
Back to top of file


How does one compile a PRO*C program?
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
NOTE: OBJS and EXE has to be entered in caps!!!
Back to top of file


How can I tell Pro*C what directory my header files are in?
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 a INCLUDE flag that can be used for this. Look at this example:
proc iname=inputfile.pc include=directory1 include=directory2...
Back to top of file


What is an indicator variable and why should I use it?
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;
Back to top of file


How does one execute PL/SQL code from Pro*C?
Example:
EXEC SQL EXECUTE
begin
dbms_application_info.set_client_info('My C Program with embedded PL/SQL');
end;
END-EXEC;
Back to top of file


Where can I get more info about the Oracle Precompilers?

 Oracle Precompilers - Online Documentation
 Oracle Precompilers Technical Bulletins
Back to top of file

No comments: