Mimer SQL Documentation TOC PREV NEXT INDEX

Mimer SQL Developer Site


General Principles for Embedding SQL Statements


The following sections discuss host languages, preprocessors, identifying SQL statements, code, comments and recommendations.

Host Languages

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.

ESQL Preprocessors

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.

UNIX: Mimer SQL supports an ESQL preprocessor for the C/C++ host language on UNIX platforms. In addition FORTRAN is supported on Linux platforms.

VMS: Mimer SQL supports an ESQL preprocessor for the COBOL, FORTRAN and C/C++ host languages on OpenVMS platforms.

Win: Mimer SQL supports an ESQL preprocessor for the C/C++ host language on Windows 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 DELETE statements must be written as:

 EXEC SQL DELETE FROM countries END-EXEC.
 EXEC SQL DELETE FROM producers END-EXEC.
 

and not

 EXEC 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.
 

The keywords EXEC SQL may not be split over more than one line.

Included Code

Any code which is included in the program by the host language compiler (as directed by host language INCLUDE statements) 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 INCLUDE statement must be used, for example:

 EXEC SQL INCLUDE 'filename'
 

Files included in this way are physically integrated into the output from the preprocessor.

Comments

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.

Recommendations

We recommend the following, when using ESQL:

Language-specific restrictions are described in Host Language Dependent Aspects.


Mimer
Mimer Information Technology AB
Voice: +46 18 780 92 00
Fax: +46 18 780 92 40
info@mimer.se
Mimer SQL Documentation TOC PREV NEXT INDEX