HP 3000 Manuals

Using the Preprocessors [ Up and Running with ALLBASE/SQL ] MPE/iX 5.0 Documentation


Up and Running with ALLBASE/SQL

Using the Preprocessors 

For large-scale database access or for batch operation, ALLBASE/SQL
includes a set of preprocessors, which let you embed SQL commands into
the source code for your own applications.  Before compiling your
program, you use the preprocessor to prepare the program for runtime
database accesses.  Separate preprocessors are available for C, COBOL,
FORTRAN, and Pascal.

Sample Application Programs 

In addition to the files for creating PartsDBE, your system includes a
set of sample application programs that use embedded SQL. You can use
option 3 from the SQLSetup menu to preprocess and compile all of the
examples for a given programming language, or you can examine a single
program at a time as shown in the next section.  The sample application
programs for MPE XL are located in SAMPLEDB.SYS, and in HP-UX, they are
found in /usr/lib/allbase/hpsql/programs.

Using the sample DBEnvironment PartsDBE installed on your system as
described earlier in this chapter, you can step through the process with
the following commands.  This example uses the C preprocessor; follow the
steps shown here for your operating system.

For HP-UX: 

First, change into the hpsql directory created when you set up the sample
DBEnvironment PartsDBE, as shown in an earlier step.  Then change into
the programs directory if it exists.  If it does not exist, create it,
then change into it as follows:

     mkdir programs
     cd programs

Issue the following commands, one at a time (some will take a few moments
to execute):

     $ rm cex2.sql Return Only needed if this file exists already. 
     $ cp /usr/lib/allbase/hpsql/programs/cex2 cex2.sql Return 
     $ psqlc ../sampledb/PartsDBE -i cex2.sql -d Return 

     Series 800:
       $ cc cex2.c -o cex2.r -lsql -lcl -lportnls Return 
     Series 300:
       $ cc cex2.c -o cex2.r -lsql -lheap2 -lportnls -lpc Return 

     $ more cex2.sql Return 
     $ more cex2.c Return 

This sequence copies the source file from the sample database directory
to the local directory, then preprocesses and compiles the program.  The
more commands let you examine the differences between the embedded SQL
source file and the preprocessor output file.

Use the following command to execute the program:

     $ ./cex2.r Return 

When prompted for part numbers, enter the following, and observe the
results:

     1123-P-01
     1323-D-01
     9999-X-01

For MPE XL: 

First, make sure you are in the group and account where PartsDBE exists.
Then issue the following commands, one at a time (some take a few moments
to execute):

     : PURGE CEX2 Return Only needed if this file exists already. 
     : FCOPY FROM=CEX2.SAMPLEDB.SYS;TO=CEX2;NEW Return 
     : PPC CEX2,PARTSDBE,CEX2P Return 
     : SAVE SQLOUT Return 
     : PRINT CEX2 Return 
     : PRINT SQLOUT Return 

This sequence copies the source file from the sample database group and
account to your local group, then preprocesses and compiles the program.
The SAVE command keeps a copy of the preprocessor output file SQLOUT in
your local group.  The PRINT commands let you examine the differences
between the embedded SQL source file and the preprocessor output file.

Use the following command to execute the program:

     : CEX2P Return 

When prompted for part numbers, enter the following, and observe the
results:

     1123-P-01
     1323-D-01
     9999-X-01



MPE/iX 5.0 Documentation