35.17. Internals#
This section explains howECPG works internally. This information can occasionally be useful to help users understand how to useECPG.
The first four lines written byecpg
to the output are fixed lines. Two are comments and two are include lines necessary to interface to the library. Then the preprocessor reads through the file and writes output. Normally it just echoes everything to the output.
When it sees anEXEC SQL
statement, it intervenes and changes it. The command starts withEXEC SQL
and ends with;
. Everything in between is treated as anSQL statement and parsed for variable substitution.
- A line number#
This is the line number of the original line; used in error messages only.
- A string#
- Input variables#
Every input variable causes ten arguments to be created. (See below.)
ECPGt_EOIT
#An
enum
telling that there are no more input variables.- Output variables#
Every output variable causes ten arguments to be created. (See below.) These variables are filled by the function.
ECPGt_EORT
#An
enum
telling that there are no more variables.
For every variable that is part of theSQL command, the function gets ten arguments:
Note that not all SQL commands are treated in this way. For instance, an open cursor statement like:
EXEC SQL OPENcursor
;
EXEC SQL BEGIN DECLARE SECTION;int index;int result;EXEC SQL END DECLARE SECTION;...EXEC SQL SELECT res INTO :result FROM mytable WHERE index = :index;
/* Processed by ecpg (2.6.0) *//* These two include files are added by the preprocessor */#include <ecpgtype.h>;#include <ecpglib.h>;/* exec sql begin declare section */#line 1 "foo.pgc" int index; int result;/* exec sql end declare section */...ECPGdo(__LINE__, NULL, "SELECT res FROM mytable WHERE index = ? ", ECPGt_int,&(index),1L,1L,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_int,&(result),1L,1L,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);#line 147 "foo.pgc"
(The indentation here is added for readability and not something the preprocessor does.)