General Principles for Embedding SQL Statements
The following sections discuss host languages, preprocessors, identifying SQL statements, code, comments and recommendations.
You can embed Mimer SQL statements in application programs written in C/C++, COBOL or FORTRAN. The basic principles for writing ESQL programs are the same in all languages and all ESQL statements are embedded in the same way.
Information given in this manual applies to all languages unless otherwise explicitly stated. Language-specific information is detailed in Host Language Dependent Aspects.
Because host language compilers do not recognize ESQL statements as valid, an ESQL preprocessor is required. An ESQL preprocessor processes the SQL statements embedded in a host language.
Linux: Mimer SQL supports an ESQL preprocessor for the C/C++ host language on Linux platforms.In addition FORTRAN is supported on Linux platforms.
VMS: Mimer SQL supports an ESQL preprocessor for the C/C++, COBOL and FORTRAN host languages on OpenVMS platforms.
Identifying SQL Statements
SQL statements are included in the host language source code exactly as though they were ordinary host language statements (i.e. they follow the same rules of conditional execution, etc., which apply to the host language).
SQL statements are identified by the leading keywords
EXEC SQL(in all host languages) and are terminated by a language-specific delimiter. Every separate SQL statement must be delimited in this way.
Blocks of several statements may not be written together within one set of delimiters. For instance, in COBOL, two consecutive
DELETEstatements must be written as:EXEC SQL DELETE FROM countries END-EXEC. EXEC SQL DELETE FROM producers END-EXEC.
and notEXEC SQL DELETE FROM countries DELETE FROM producers END-EXEC.
Single SQL statements can however be split over several lines, following the host language rules for line continuation.
The following embedded statement is thus acceptable in a FORTRAN program (the continuation mark is a
+in column 6 on the second line):EXEC SQL DELETE FROM countries + WHERE code = 'BA' END-EXEC.
EXEC SQLmay not be split over more than one line.
Any code which is included in the program by the host language compiler (as directed by host language
INCLUDEstatements) is not recognized by the ESQL preprocessor.
If external source code modules containing SQL statements are to be included in the program, the non-standard
SQL INCLUDEstatement must be used, for example:EXEC SQL INCLUDE 'filename'
Files included in this way are physically integrated into the output from the preprocessor.
Comments may be written in the ESQL program according to the rules for writing comments in the host language. Thus comments may be written within an SQL statement if the host language accepts comments within host language statements.
The following statement is valid in C/C++:exec sql DELETE FROM countries /* Remove Bosnia and Herzegovina */ WHERE code = 'BA';
Note: The keywords EXEC and SQL may not be separated by a comment.
We recommend the following, when using ESQL:
- Avoid variable names beginning with the letters
SQLCODE, which should be used when appropriate).
- Avoid subroutine or subprogram names ending with a number.
Language-specific restrictions are described in Host Language Dependent Aspects.
Mimer Information Technology AB
Voice: +46 18 780 92 00
Fax: +46 18 780 92 40