Personal tools
You are here: Home Classes Spring 2006 CS 311 PROC.htm
Document Actions

PROC.htm

by bob last modified 2006-04-28 16:18

Using PRO*C
(Oracle's C interface)

To access an Oracle database through a C program, you need to use PRO*C. This works in two steps. Enter the extended C program into a file called foo.pc. Run this file through the program proc, which converts foo.pc into a standard C program foo.c This can then be compiled and linked to all of the necessary libraries. The following Makefile handles all of this:


ORACLE = /usr/users/noquota/oracle
IFLAG = -I $(ORACLE)/precomp/public
LFLAG = -L $(ORACLE)/lib32
LIBS = -lclntsh `cat $(ORACLE)/lib32/ldflags` `cat $(ORACLE)/lib32/sysliblist` -R $(ORACLE)/lib32
OTHERS = -laio -lposix4 -lm -lthread
ALL_FLAGS = $(IFLAG) $(LFLAG) $(LIBS) $(OTHERS)

%: %.pc
proc $@.pc
gcc $@.c -o $@ $(ALL_FLAGS)

This compiles extended C file foo.pc into executable file foo if you just type
                make foo

Within your program every sql statement is preceded by the phrase EXEC SQL. You can use C-variables within SQL statements if you put a colon in front of them, as in

int x;

EXEC SQL SELECT COUNT(*) INTO :x FROM Faculty;

This allows you to intermingle C and SQL computations fairly easily. Beware that the proc converter will accept conditional compilation (#if) directives, but it does not accept #define directives; you have to make explicit constants rather than using the C-preprocessor.

There is some reasonable documentation for all of this. The Stanford notes on PROC*C are pretty good. The Oracle documentation is not particularly well written, but it is fairly complete. There is a directory of example programs that came with the Oracle implementation

at /usr/users/noquota/oracle/precomp/demo/proc.

 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: