General Rules for Embedding SQL [ ALLBASE/SQL FORTRAN Application Programming Guide ] MPE/iX 5.0 Documentation
ALLBASE/SQL FORTRAN Application Programming Guide
General Rules for Embedding SQL
Embedded SQL commands must appear in certain locations within the FORTRAN
program. Each embedded SQL command must be accompanied by the prefix
EXEC SQL. Comments may be placed within an embedded command, and an
embedded SQL command may continue for several lines.
An embedded SQL command has no maximum length. A dynamic SQL command can
be no longer than 2048 bytes.
Location of SQL Commands
Put SQL commands, including their prefix, within columns 7 through 72 of
either the main program unit or a subprogram unit:
* INCLUDE SQLCA must appear in the Type Declaration Section of the
program unit which contains embedded SQL statements. The INCLUDE
command must appear before the BEGIN DECLARE SECTION command.
* BEGIN DECLARE SECTION and END DECLARE SECTION must appear as the
last declaration in the Type Declaration Section of the program
unit which contains embedded SQL statements. No variable type
declarations are allowed after the END DECLARE SECTION command.
* All other SQL commands may appear after the END DECLARE SECTION in
either the main program unit or a subprogram unit.
Prefix
Precede each SQL command with the prefix EXEC SQL. Minimally the prefix
must be specified on the same line. For example, the following are
legal:
EXEC SQL SELECT PartName INTO :PartName
1 FROM PurchDB.Parts WHERE PartNumber = :PartNumber
EXEC SQL
1 SELECT PartName
2 INTO :PartName
3 FROM PurchDB.Parts
4 WHERE PartNumber = :PartNumber
However, the following is not legal:
EXEC
1 SQL SELECT PartName INTO :PartName
2 FROM PurchDB.Parts WHERE PartNumber = :PartNumber
FORTRAN Comments
You may insert FORTRAN comment lines within or between embedded SQL
commands. Denote comment lines by placing the letter C in column 1 and
entering the comment in columns 7 through 72:
EXEC SQL SELECT PartNumber, PartName
C put the data into the following host variables
1 INTO :PartNumber, :PartName
C find the data in the following table
2 FROM PurchDB.Parts
C retrieve only data that satisfies this search condition
3 WHERE PartNumber = :PartNumber
SQL Comments
SQL comments can be inserted in any line of an SQL statement, except the
last line, by prefixing the comment character with at least one space
followed by two hyphens followed by one space:
EXEC SQL SELECT * FROM PurchDB.Parts -- This code selects Parts Table values.
WHERE SalesPrice > 500.;
The comment terminates at the end of the current line. (The decimal
point in the 500 improves performance when being compared to SalesPrice,
which also has a decimal; no data type conversion is necessary.)
Continuation Lines
The FORTRAN preprocessor allows you to continue a non-numeric literal
from one line to the next. Enter any character other than the digit 0 or
a blank in column 6, and do not enter the character C, *, or $ in column
1. The FORTRAN preprocessor supports up to 19 continuation lines. The
the FORTRAN/XL compiler allows you to extend the number of continuation
lines, the FORTRAN compiler on other systems where the preprocessor is
used does not allow more than 19 contination lines. Therefore, for
consistency, the preprocessor only allows 19 contination lines.
IF (PREDEFINEDCOMMENT .EQ. '5') THEN
EXEC SQL INSERT INTO PURCHDB.VENDORS
1 (VendorRemarks)
2 VALUES ('This vendor is bad news. Definitely place
3 no orders.')
ELSE
EXEC SQL INSERT INTO PURCHDB.VENDORS
1 (VendorRemarks)
2 VALUES (:VendorRemarks)
ENDIF
MPE/iX 5.0 Documentation