 |
» |
|
|
 |
The FORTRAN preprocessor that is part of ALLBASE/SQL is
specifically for FORTRAN 77 programs. Although the preprocessor
ignores FORTRAN statements in your source code, it generates
FORTRAN statements, based on embedded SQL commands.
Figure 1-3 “Preprocess-Time Events” summarizes the four main preprocess-time events:
Syntax checking of SQL commands and host variable declarations.
Creation of compilable files: one modified source code file
and one include file.
Creation of an installable module.
Storage of a module in the system catalog.
Effect of Preprocessing on Source Code |  |
The FORTRAN preprocessor scans the source code for SQL commands.
If the syntax of an SQL command is valid, the preprocessor
converts the command to compilable FORTRAN statements that call
ALLBASE/SQL external procedures at runtime. During
preprocessing, for example, the SQL command:
EXEC SQL SELECT PartNumber, PartName, SalesPrice
1 INTO :PartNumber,
2 :PartName,
3 :SalesPrice
4 FROM Purchdb.Parts
5 WHERE PartNumber = :PartNumber
|
is converted into the following modified source code statements.
The converted statements are shown in the coded statements below.
The shaded areas show where the original code is commented out and
the preprocessor generated code is added.
C**** Start SQL Preprocessor ****
C EXEC SQL SELECT PartNumber, PartName, SalesPrice
C 1 INTO :PartNumber,
C 2 :PartName,
C 3 :SalesPrice :SalesPriceInd
C 4 FROM Purchdb.Parts
C 5 WHERE PartNumber = :PartNumber
C
C**** Start Inserted Statements ****
WRITE(SQLTMP,'(A16)')PartNumber
CALL SQLXFE(SQLCAID,SQLOWN,SQLMDN,1,SQLTMP,16,56,1)
IF (SQLCODE .EQ. 0) THEN
READ(SQLTMP,'(A16,A30,A8,A2)')PartNumber,PartName,
SalesPrice,Sales
1PriceInd
ELSE
END IF
C**** END SQL PREPROCESSOR ****
|
 |
The embedded SELECT command has been converted into a FORTRAN
comment, and FORTRAN statements that enable ALLBASE/SQL to
execute the SELECT command at runtime have been inserted. The
names that appear in the inserted FORTRAN code
identify variables used by the ALLBASE/SQL
external procedures; in this example, the names identify
variables used by the SQLXFE external procedure. Some of these
variables are derived from host variables. As
shown in the embedded SELECT command above, you precede a host
variable with a colon when you use it in SQL commands:
 |
Type declarations used by preprocessor generated code are
defined and initialized in the include file the preprocessor
creates. The name of the include file is derived from the preprocessor's
output file name followed by a period and the suffix .sqlv; for example
ModifiedSourceFileName.sqlv. The preprocessor inserts INCLUDE statements that
reference this file in each program unit of the modified source
code after the host variable declarations. Even if you do not
declare host variables you must still include the EXEC SQL BEGIN
DECLARE SECTION and EXEC SQL END DECLARE SECTION commands in
order for the preprocessor to create and insert an include
file with this syntax:
INCLUDE 'ModifiedSourceFileName.sqlv'
|
 |  |  |  |  | CAUTION: Never modify the statements inserted by the preprocessor in the
modified source code file, or the include file the preprocessor
creates. Changes to preprocessor generated information could
damage your DBEnvironment or your system.
|  |  |  |  |
Effect of Preprocessing on DBEnvironments |  |
When you invoke the preprocessor, you name an ALLBASE/SQL
DBEnvironment. The preprocessor starts a DBE session for that
DBEnvironment when preprocessing begins and terminates that
session when preprocessing ends.
When the preprocessor encounters a syntactically correct SQL
command, it creates a section and stores that section in the
system catalog of the DBEnvironment being accessed. An
ALLBASE/SQL section is a group of stored ALLBASE/SQL
instructions for executing one SQL command.
All sections created during a preprocessing session constitute a
module. The preprocessor derives the name of the
module from the PROGRAM statement or subroutine name unless you
supply a different name when you invoke the preprocessor:
$ psqlfor DBEnvironment -m mymodulename -i SourceFileName.sql -p ModifiedSourceFileName.f
|
When the preprocessor terminates its DBEnvironment session, it
issues a COMMIT WORK command if it encountered no errors.
Created sections are stored in the system catalog and associated
with the module name.
|