Configuring Your Pro*C Environment
Configuration is actually a two-part process. The first step
is to configure your Pro*C environment, and after that is complete, configure
Visual C++ so that the generated .c file will successfully compile, link, and
run.
Oracle did a poor job of stating all of the necessary steps
to configure your environment. There are some fairly obscure references to what
is needed, and what is provided (the project files in the demo area) more than
likely needs adjusting.
The .c files can be generated in one of two ways: via the
command line or by using a GUI tool Oracle provides. To keep things simple, I
will use the command line interface (using the "proc" command) and the pcscfg.cfg
configuration file found in precomp\admin. With a properly configured pcscfg.cfg
file, all that will be needed to generate the .c file is a simple "proc iname=input_file_name.pc"
at the command prompt.
Assuming you are using the Scott/Tiger schema, your
ORACLE_HOME is in C:\ora9i, and you have Visual C++ in C:\Program Files, this
is what you need in the configuration file:
define=(WIN32_LEAN_AND_MEAN)
include=(C:\Program Files\Microsoft
Visual Studio\VC98\Include)
include=(c:\ora9i\precomp\PUBLIC)
include=(C:\ora9i\precomp\lib\msvc)
SQLCHECK=SEMANTICS
USERID=SCOTT/TIGER
Let's use the sample9 project (it extracts data based on the
department number you provide). Change directory to sample9 in the demo\proc
area. To create the sample9.c file, at the command prompt, enter
proc iname=sample9.pc
You should have a sample9.c file now. Earlier, I alluded to
the fact that the .c file was "kind of sort of" already present. In a text
editor such as TextPad (yes, it is a shameless plug), open the sample9.pc and
sample9.c files and note the huge difference between them.
Configuring the Visual C++ Environment
If you are familiar with Visual Studio and jumped ahead, you
will have noticed that the sample9.c file compiles okay, but fails to link.
Here are the steps to enable a successful compile-link-run process:
1) Add the Pro*C executable to the Executable files
directory
2) Add the Pro*C include files to the Include files
directory
3) Add the path to oraSQL9.lib to the Library files
directory
4) Add the Oracle library to the link line
Double-click the sample9.c file to start Visual C++. You
should end up with a window like this:
Go to Tools>Options and select the Directories tab. Add
the path to your ORACLE_HOME\bin directory (C:\ora9i\bin in my case) under the
Executable files menu option for "Show directories for." Change the menu option
to Include files and enter ORACLE_HOME\precomp\public. Change the menu option
to Library files and enter ORACLE_HOME\precomp\lib\msvc (there should be a file
named oraSQL9.lib there).
Adding the path for proc
Adding the path for the Pro*C include files
Adding the path for the oraSQL9.lib file
Add the oraSQL9.lib file to the Object/library modules under
the Link tab in Project>Settings.
You are now ready to link and run. What sample9.exe does is
shown below.
Okay, the results aren't that impressive, but if there were
millions of rows, how well Pro*C, via C, performs may make you sit up and pay
attention to what the utility can offer with respect to shaving significant
amounts of time off of a query.
In Closing
With a little bit of C and a little bit of Oracle, you now
have at your disposal the means to work outside of Oracle and create an
application whose interface with Oracle is transparent to a user. In the next
part of this series, I will demonstrate how you can build your own version of
SQL*Loader.
»
See All Articles by Columnist Steve Callan