©
This document usesPHP Chinese website manualRelease
To include an external file into your embedded SQL program, use:
EXEC SQL INCLUDEfilename;
The embedded SQL preprocessor will look for a file namedfilename.h, preprocess it, and include it in the resulting C output. Thus, embedded SQL statements in the included file are handled correctly.
Note that this isnotthe same as:
#include <filename.h>
because this file would not be subject to SQL command preprocessing. Naturally, you can continue to use the C#includedirective to include other header files.
Note:The include file name is case-sensitive, even though the rest of theEXEC SQL INCLUDEcommand follows the normal SQL case-sensitivity rules.
Similar to the directive#definethat is known from C, embedded SQL has a similar concept:
EXEC SQL DEFINEname; EXEC SQL DEFINEnamevalue;
So you can define a name:
EXEC SQL DEFINE HAVE_FEATURE;
And you can also define constants:
EXEC SQL DEFINE MYNUMBER 12; EXEC SQL DEFINE MYSTRING 'abc';
Useundefto remove a previous definition:
EXEC SQL UNDEF MYNUMBER;
Of course you can continue to use the C versions#defineand#undefin your embedded SQL program. The difference is where your defined values get evaluated. If you useEXEC SQL DEFINEthen theecpgpreprocessor evaluates the defines and substitutes the values. For example if you write:
EXEC SQL DEFINE MYNUMBER 12; ... EXEC SQL UPDATE Tbl SET col = MYNUMBER;
thenecpgwill already do the substitution and your C compiler will never see any name or identifierMYNUMBER. Note that you cannot use#definefor a constant that you are going to use in an embedded SQL query because in this case the embedded SQL precompiler is not able to see this declaration.
You can use the following directives to compile code sections conditionally:
Checks anameand processes subsequent lines ifnamehas been created withEXEC SQL definename.
Checks anameand processes subsequent lines ifnamehasnotbeen created withEXEC SQL definename.
Starts processing an alternative section to a section introduced by eitherEXEC SQL ifdefnameorEXEC SQL ifndefname.
Checksnameand starts an alternative section ifnamehas been created withEXEC SQL definename.
Ends an alternative section.
Example:
EXEC SQL ifndef TZVAR; EXEC SQL SET TIMEZONE TO 'GMT'; EXEC SQL elif TZNAME; EXEC SQL SET TIMEZONE TO TZNAME; EXEC SQL else; EXEC SQL SET TIMEZONE TO TZVAR; EXEC SQL endif;