Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
36.17. Internals
Prev UpChapter 36. ECPG — EmbeddedSQL in CHome Next

36.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.

Variable substitution occurs when a symbol starts with a colon (:). The variable with that name is looked up among the variables that were previously declared within aEXEC SQL DECLARE section.

The most important function in the library isECPGdo, which takes care of executing most commands. It takes a variable number of arguments. This can easily add up to 50 or so arguments, and we hope this will not be a problem on any platform.

The arguments are:

A line number#

This is the line number of the original line; used in error messages only.

A string#

This is theSQL command that is to be issued. It is modified by the input variables, i.e., the variables that where not known at compile time but are to be entered in the command. Where the variables should go the string contains?.

Input variables#

Every input variable causes ten arguments to be created. (See below.)

ECPGt_EOIT#

Anenum 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#

Anenum 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;

is not copied to the output. Instead, the cursor'sDECLARE command is used at the position of theOPEN command because it indeed opens the cursor.

Here is a complete example describing the output of the preprocessor of a filefoo.pgc (details might change with each particular version of the preprocessor):

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;

is translated into:

/* 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.)


Prev Up Next
36.16. Oracle Compatibility Mode Home Chapter 37. The Information Schema
pdfepub
Go to PostgreSQL 16
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp