バージョンごとのドキュメント一覧

36.17. 内部 #

<title>Internals</title>

This section explains how <application>ECPG</application> works internally. This information can occasionally be useful to help users understand how to use <application>ECPG</application>. 本節では内部的なECPGの動作を説明します。 この情報はECPGの使用方法を理解する手助けとして有用なことがあります。

The first four lines written by <command>ecpg</command> 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. ecpgによって出力に書き込まれる最初の4行は固定されています。 2行はコメントで、残り2行はライブラリとのインタフェースのために必要なインクルード行です。 その後、プリプロセッサはファイル全体を読み取り、出力に書き出します。 通常は、単にすべてそのまま出力に書き出します。

When it sees an <command>EXEC SQL</command> statement, it intervenes and changes it. The command starts with <command>EXEC SQL</command> and ends with <command>;</command>. Everything in between is treated as an <acronym>SQL</acronym> statement and parsed for variable substitution. EXEC SQLを検出すると、間に入り、それを変更します。 このコマンドはEXEC SQLで始まり、;で終わります。 この間のすべてはSQL文として扱われ、変数の置換のために解析されます。

Variable substitution occurs when a symbol starts with a colon (<literal>:</literal>). The variable with that name is looked up among the variables that were previously declared within a <literal>EXEC SQL DECLARE</literal> section. 変数置換は、シンボルがコロン(:)から始まる場合に発生します。 その名前の変数が、EXEC SQL DECLAREセクションで事前に宣言された変数の中から検索されます。

The most important function in the library is <function>ECPGdo</function>, 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. ライブラリ内で最も重要な関数はECPGdoです。 これが、ほとんどのコマンドの実行を管理します。 可変長の引数をとります。 すべてのプラットフォームで問題にならないことを祈っていますが、これは50程度の引数まで簡単に追加できます。

The arguments are: 引数を以下に示します。

行番号 #

This is the line number of the original line; used in error messages only. 元の行の行番号です。 エラーメッセージ内でのみ使用されます。

文字列 #

This is the <acronym>SQL</acronym> 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 <literal>?</literal>. 発行すべきSQLコマンドです。 入力変数、つまり、コンパイル時に未知だったがそのコマンド内に与えるべき変数によって変更されます。 変数が文字列内に挿入される箇所は?となっています。

入力変数 #

Every input variable causes ten arguments to be created. (See below.) すべての入力変数は10個の引数を作成します(後述)。

ECPGt_EOIT #

An <type>enum</type> telling that there are no more input variables. 入力変数がもうないことを表すenumです。

出力変数 #

Every output variable causes ten arguments to be created. (See below.) These variables are filled by the function. すべての出力変数は10個の引数を作成します(後述)。 これらの変数は関数によって埋められます。

ECPGt_EORT #

An <type>enum</type> telling that there are no more variables. 変数がもうないことを表すenumです。

For every variable that is part of the <acronym>SQL</acronym> command, the function gets ten arguments: SQLコマンドの一部となるすべての変数に対して、この関数は以下の10個の引数を生成します。

  1. The type as a special symbol. 特別シンボルとしての型。

  2. A pointer to the value or a pointer to the pointer. 値へのポインタ、もしくはポインタのポインタ。

  3. The size of the variable if it is a <type>char</type> or <type>varchar</type>. 変数がcharvarcharの場合はそのサイズ。

  4. The number of elements in the array (for array fetches). 配列の要素数(配列取り出し用)。

  5. The offset to the next element in the array (for array fetches). 配列の次の要素のオフセット(配列取り出し用)。

  6. The type of the indicator variable as a special symbol. 特別シンボルとしての指示子変数の型。

  7. A pointer to the indicator variable. 指示子変数へのポインタ。

  8. 0

  9. The number of elements in the indicator array (for array fetches). 指示子配列内の要素数(配列取り出し用)。

  10. The offset to the next element in the indicator array (for array fetches). 指示子配列内の次要素へのオフセット(配列取り出し用)。

Note that not all SQL commands are treated in this way. For instance, an open cursor statement like: すべてのSQLコマンドがこの方法で扱われるわけではないことに注意してください。 例えば、以下のカーソルを開くSQL文は出力にコピーされません。

EXEC SQL OPEN cursor;

is not copied to the output. Instead, the cursor's <command>DECLARE</command> command is used at the position of the <command>OPEN</command> command because it indeed opens the cursor. その代わりにカーソルのDECLAREコマンドがOPENコマンドの場所で使用されます。 実際にこのコマンドがカーソルを開くからです。

Here is a complete example describing the output of the preprocessor of a file <filename>foo.pgc</filename> (details might change with each particular version of the preprocessor): 以下に、foo.pgcファイルに対するプリプロセッサの出力を完全に説明する例を示します (プリプロセッサのバージョンによって詳細が異なっているかもしれません)。

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.) ここで可読性のためにインデントを付けています。 プリプロセッサが行ったものではありません。