ESQL in FORTRAN Programs
Mimer SQL supports ESQL for ANSI FORTRAN-90 fixed format.
Source statements must be provided as fixed format, 80 byte records.
SQL Statement Format
The following sections discuss the SQL statement format.
The leading delimiter
EXEC SQLidentifies SQL statements. The end of an SQL statement is marked by the end of the line when the following line does not begin with a continuation character. The FORTRAN-90 statement delimiter
;can also be used.
ExampleEXEC SQL DELETE FROM countries
Statements (including delimiters) may be written anywhere between positions 7 and 72 inclusive.
Line continuation rules for SQL statements are the same as those for ordinary FORTRAN statements. The continuation character is any character except space and 0 (zero) in position 6. The FORTRAN limitation of a maximum of 19 continuation lines per statement does not apply within SQL statements.
For a string constant, a white-space character (ASCII HEX-values 09 - 0D, or 20, i.e.
<TAB>, <LF>, <VT>, <FF>, <CR> or <SP>), can be used to join two or more substrings. Each substring must be separately enclosed in delimiters.
Examples:EXEC SQL SELECT CODE, CURRENCY + FROM MIMER_STORE.CURRENCIES + WHERE CODE LIKE :CODE EXEC SQL COMMENT ON TABLE CURRENCIES IS + 'Holds currency'<CR> + ' details'
Any labeled SQL statement in the source code will generate a CONTINUE statement during preprocessing. Declarative SQL statements used before the first executable SQL statement should not be labeled.
Comment lines, marked by
Cin position 1, may be written within SQL statements. The whole line following a comment mark is treated as a comment, and the following line must either be another comment or follow the continuation rules given above.
Note: Lines that are completely blank are not treated as comments by the
ESQL/FORTRAN preprocessor. The absence of a continuation character indicates the end of the previous statement, and a completely blank line may be used to structure comments in the output from the preprocessor. See Preprocessor Output Format for details.
FORTRAN-90 style comments may also be used, marked by the
!character (the text between the
!and the end-of-line is treated as a comment).
Debugging lines (marked with a
Din position 1) are treated as comments by the preprocessor.
The following sections discuss declarations, SQL data type correspondence, value assignments, preprocessor output format and scope.
Host variables used in SQL statements must be declared within the
SQL DECLARE SECTION, delimited by the statements
BEGIN DECLARE SECTIONand
END DECLARE SECTION.
Variables declared within the
SQL DECLARE SECTIONmust conform to the following rules in order to be recognized by the SQL preprocessor:
- any valid FORTRAN variable name may be used.
- variables must be scalar variables (i.e. they may not be elements of vectors or arrays).
- implicit declaration by means of the
IMPLICITstatement or default typing may not be used.
- FORTRAN COMPLEX variables may not be used.
- character variables must be declared with a fixed constant length. Expressions and variable length declarations (such as
CHARACTER*(*)) may not be used.
- indicator variables should be declared as
A syntax diagram showing the variable declarations recognized by the ESQL/FORTRAN preprocessor is given below:
The data type declaration must be separated from the variable name by at least one space (which is not required in FORTRAN declarations outside the
SQL DECLARE SECTION).
Thus the declaration:INTEGER*2A
is not recognized. The required formulation is:INTEGER*2 A
Lists of variables following a single default data type declaration are accepted. Any declarations in a list that are not valid in SQL contexts are ignored by the preprocessor. Thus, the following statement declares variables
INTEGER*2for use in SQL statements, while the array
Cis ignored:INTEGER*4 A, B*2, C(10), D
SQL Data Type Correspondence
Valid host data types are listed below for each of the data types used in SQL statements.
The following additional points should be noted:
- FORTRAN does not support
DECIMALdata types. A string of digits including a decimal point is interpreted as a
REALconstant in FORTRAN. Exponential notation should always be used to specify floating point values in SQL statements.
DOUBLE PRECISIONconstants may be written with a
Das the exponent marker in FORTRAN (e.g.
1.23D+02). The only permissible exponent marker within SQL statements is E (e.g.
The general rules for conversion of values between compatible but different data types, see of the Mimer SQL Reference Manual, apply to the transfer of data between the database and host variables, with the data type correspondence as given in the table above.
Preprocessor Output Format
Output from the ESQL/FORTRAN preprocessor retains SQL statements from the original source code as comments. The output follows the ANSI standard for record format, and should be compiled with a FORTRAN compiler set to accept ANSI standard. Comments within SQL statements are retained exactly as written.
Completely blank lines between SQL statements and following comments cause the preprocessor to write the comments after the generated SQL call. Otherwise comments immediately following SQL statements are output before the generated call. Debugging lines (using
Din position 1) remain unchanged after preprocessing.
The preprocessed code is structured to reflect the structuring of the original source code.
Host variables follows the same scope rules as ordinary variables in FORTRAN.
SQL descriptor names, cursor names and statement names must be unique within the compilation unit.
A compilation unit for FORTRAN is the same as a routine.
Mimer Information Technology AB
Voice: +46 18 780 92 00
Fax: +46 18 780 92 40