2 ECPGPlus - Overview

Table of Contents Previous Next


2 ECPGPlus - Overview

ecpg_path
To produce an executable from a C program that contains embedded SQL statements, pass the program (my_program.pgc in the diagram above) to the ECPGPlus pre-compiler. ECPGPlus translates each SQL statement in my_program.pgc into C code that calls the ecpglib API, and produces a C program (my_program.c). Then, pass the C program to a C compiler; the C compiler generates an object file (my_program.o). Finally, pass the object file (my_program.o), as well as the ecpglib library file, and any other required libraries to the linker, which in turn produces the executable (my_program).
While the ECPGPlus preprocessor validates the syntax of each SQL statement, it cannot validate the semantics. For example, the preprocessor will confirm that an INSERT statement is syntactically correct, but it cannot confirm that the table mentioned in the INSERT statement actually exists.
C preprocessor directives may be interpreted or ignored; the option is controlled by a command line option (-C PROC) entered when you invoke ECPGPlus. In either case, ECPGPlus copies each C preprocessor directive to the output file (4) without change; any C preprocessor directive found in the source file will appear in the output file.
C declarations are copied to the output file without change, except that each VARCHAR declaration is translated into an equivalent struct declaration.
Lines 10 through 14 contain an embedded-SQL declaration section.

C variables that you refer to within SQL code are known as
host variables. If you invoke the ECPGPlus preprocessor in Pro*C mode (-C PROC), you may refer to any C variable within a SQL statement; otherwise you must declare each host variable within a BEGIN/END DECLARATION SECTION pair.
Any SQL statement must be prefixed with EXEC SQL and extends to the next (unquoted) semicolon. For example:

2 ECPGPlus - Overview

Table of Contents Previous Next