C-preprocessor directives v15
The ECPGPlus C-preprocessor enforces two behaviors that depend on the mode in which you invoke ECPGPlus:
PROC
mode- Non-
PROC
mode
Compiling in PROC mode
In PROC
mode, ECPGPlus allows you to:
- Declare host variables outside of an
EXEC SQL BEGIN/END DECLARE SECTION
. - Use any C variable as a host variable as long as its data type is compatible with ECPG.
When you invoke ECPGPlus in PROC
mode (by including the -C PROC
keywords), the ECPG compiler honors the following C-preprocessor directives:
Preprocessor directives are used to affect or direct the code that's received by the compiler. For example, consider the following code sample:
Suppose you invoke ECPGPlus with the following command-line arguments:
ECPGPlus copies the entire fragment, without change, to the output file. It sends only the following tokens to the ECPG parser:
On the other hand, suppose you invoke ECPGPlus with the following command-line arguments:
The ECPG parser receives the following tokens:
If your code uses preprocessor directives to filter the code that's sent to the compiler, the complete code is retained in the original code, while the ECPG parser sees only the processed token stream.
You can also use compatible syntax when executing the following preprocessor directives with an EXEC
directive:
For example, suppose your code includes the following:
You invoke ECPGPlus with the following command-line arguments:
ECPGPlus sends the following tokens to the output file and the ECPG parser:
Note
The EXEC ORACLE
preprocessor directives work only if you specify -C PROC
on the ECPG command line.
Using the SELECT_ERROR precompiler option
When using ECPGPlus in compatible mode, you can use the SELECT_ERROR
precompiler option to tell your program how to handle result sets that contain more rows than the host variable can accommodate. The syntax is:
The default value is YES
. A SELECT
statement returns an error message if the result set exceeds the capacity of the host variable. Specify NO
to suppress error messages when a SELECT
statement returns more rows than a host variable can accommodate.
Use SELECT_ERROR
with the EXEC ORACLE OPTION
directive.
Compiling in non-PROC mode
If you don't include the -C PROC
command-line option:
- C preprocessor directives are copied to the output file without change.
- You must declare the type and name of each C variable that you intend to use as a host variable in an
EXEC SQL BEGIN/END DECLARE
section.
When invoked in non-PROC
mode, ECPG implements the behavior described in the PostgreSQL core documentation.