4 This section explains how ECPG works internally. This information can
5 occasionally be useful to help users understand how to use ECPG.
7 The first four lines written by ecpg to the output are fixed lines. Two
8 are comments and two are include lines necessary to interface to the
9 library. Then the preprocessor reads through the file and writes
10 output. Normally it just echoes everything to the output.
12 When it sees an EXEC SQL statement, it intervenes and changes it. The
13 command starts with EXEC SQL and ends with ;. Everything in between is
14 treated as an SQL statement and parsed for variable substitution.
16 Variable substitution occurs when a symbol starts with a colon (:). The
17 variable with that name is looked up among the variables that were
18 previously declared within a EXEC SQL DECLARE section.
20 The most important function in the library is ECPGdo, which takes care
21 of executing most commands. It takes a variable number of arguments.
22 This can easily add up to 50 or so arguments, and we hope this will not
23 be a problem on any platform.
28 This is the line number of the original line; used in error
32 This is the SQL command that is to be issued. It is modified by
33 the input variables, i.e., the variables that where not known at
34 compile time but are to be entered in the command. Where the
35 variables should go the string contains ?.
38 Every input variable causes ten arguments to be created. (See
42 An enum telling that there are no more input variables.
45 Every output variable causes ten arguments to be created. (See
46 below.) These variables are filled by the function.
49 An enum telling that there are no more variables.
51 For every variable that is part of the SQL command, the function gets
53 1. The type as a special symbol.
54 2. A pointer to the value or a pointer to the pointer.
55 3. The size of the variable if it is a char or varchar.
56 4. The number of elements in the array (for array fetches).
57 5. The offset to the next element in the array (for array fetches).
58 6. The type of the indicator variable as a special symbol.
59 7. A pointer to the indicator variable.
61 9. The number of elements in the indicator array (for array fetches).
62 10. The offset to the next element in the indicator array (for array
65 Note that not all SQL commands are treated in this way. For instance,
66 an open cursor statement like:
69 is not copied to the output. Instead, the cursor's DECLARE command is
70 used at the position of the OPEN command because it indeed opens the
73 Here is a complete example describing the output of the preprocessor of
74 a file foo.pgc (details might change with each particular version of
76 EXEC SQL BEGIN DECLARE SECTION;
79 EXEC SQL END DECLARE SECTION;
81 EXEC SQL SELECT res INTO :result FROM mytable WHERE index = :index;
84 /* Processed by ecpg (2.6.0) */
85 /* These two include files are added by the preprocessor */
86 #include <ecpgtype.h>;
89 /* exec sql begin declare section */
95 /* exec sql end declare section */
97 ECPGdo(__LINE__, NULL, "SELECT res FROM mytable WHERE index = ? ",
98 ECPGt_int,&(index),1L,1L,sizeof(int),
99 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
100 ECPGt_int,&(result),1L,1L,sizeof(int),
101 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
105 (The indentation here is added for readability and not something the