開発者の方のために

78) This section is for those who want to develop the ecpg interface. It describes how the things work. The ambition is to make this section contain things for those that want to have a look inside and the section on How to use it should be enough for all normal questions. So, read this before looking at the internals of the ecpg. If you are not interested in how it really works, skip this section. ※ The ambition is to make 〜 → for those that = for those who (?)

このセクションは ecpg インターフェースの開発をしたい方へのもので, それぞれがどのように動作するのかを説明します. 内部構造を見てみたい方のために道具を用意することがこのセクションへの思いです. 一般的な疑問に対しては,すべて「ecpg の使い方」のセクションで十分なはずです. ですからこのセクションは ecpg の内部を見てみる前に読んで下さい. 実際にどのような動作をしているのかということが問題でなければ, このセクションは読み飛ばしても構いません.

今後しなければならないこと

80) This version the preprocessor has some flaws:

現バージョンのプリプロセッサには少し不備な点があります:

ライブラリ関数

82) to_date et al. do not exists. But then Postgres has some good conversion routines itself. So you probably won't miss these.

to_date などが存在しません.しかし Postgres 自体すぐれた変換ルーチンを持っていますから,まず困ることはないでしょう.

構造体と共用体

84) Structures and unions have to be defined in the declare section.

構造体と共用体を宣言セクションで定義しなければなりません.

未実装の構文

86) The following statements are not implemented thus far: ※ thus far = 今まで ≒(この文脈では)今も (?)

今も以下の構文が実装されていません.

exec sql allocate

exec sql deallocate

SQLSTATE

'no data found(データが見つかりません)' メッセージ

88) The error message for "no data" in an exec sql insert select from statement has to be 100. ※よくわかりません (??)

exec sql insert/select from 文における "no data" エラーメッセージは 100 でなければなりません.

sqlwarn[6]

89) sqlwarn[6] should be 'W' if the PRECISION or SCALE value specified in a SET DESCRIPTOR statement will be ignored.

sqlwarn[6] は SET DESCRIPTOR 文で指定された PRECISION,または SCALE の値が無視された場合 'W' であるべきですがそうなっていません.

プリプロセッサ

91) The first four lines written to the output are constant additions by ecpg. These are two comments and two include lines necessary for the interface to the library.

出力に書き込まれる最初の四行は ecpg が付け加え,常に一定の内容です. ここは二行のコメントと,ライブラリとの連携に必要な二行の #include になっています.

92) Then the preprocessor works in one pass only, reading the input file and writing to the output as it goes along. Normally it just echoes everything to the output without looking at it further. ※ as it goes along(?) ※ Normally it just echoes 〜 は, 埋め込み SQL 以外の部分をそのまま出力するという意味?

プリプロセッサは入力ファイルを読み込み, 出力ファイルに書き出す1パスだけで動作します. 通常は後先を見ずに単に(そのまま)すべてを出力します.

93) When it comes to an EXEC SQL statements it intervenes and changes them depending on what it is. The EXEC SQL statement can be one of these:

プリプロセッサが EXEC SQL 文にたどり着くと入出力の間に入り, 文の内容に従って変更を加えます.

宣言セクション

95) Declare sections begins with

宣言セクションは

exec sql begin declare section;
で始まり, 96) and ends with
exec sql end declare section;
で終わります. 97) In the section only variable declarations are allowed. Every variable declare within this section is also entered in a list of variables indexed on their name together with the corresponding type. ※ declare -> declared(?) このセクションで許されているのは変数の宣言だけです. セクション内で宣言された個々の変数は同時に変数リストに加えられます. リストは変数の名前をインデックスにしており,対応する変数の型も一緒に持ちます.

98) In particular the definition of a structure or union also has to be listed inside a declare section. Otherwise ecpg cannot handle these types since it simply does not know the definition.

特に構造体と共用体の定義も宣言セクションの内部に並べなくてはなりません. さもないと ecpg はその定義について何も知らないことになるので, これらの型を扱うことができなくなります.

99) The declaration is echoed to the file to make the variable a normal C-variable also.

宣言も変数を通常の C の変数にしてファイルに出力します.

100) The special types VARCHAR and VARCHAR2 are converted into a named struct for every variable. A declaration like:

特別な型,VARCHAR と VARCHAR2 は変数ごとに名前のついた構造体に変換されます. 宣言は以下のようになります:

VARCHAR var[180];
101) is converted into そしてこれは,
struct varchar_var { int len; char arr[180]; } var;
と変換されます.

Include 文

103) An include statement looks like:

include 文は以下のようになります:

exec sql include filename;
104) Not that this is NOT the same as ※ Not -> Note(?) これは
#include <filename.h>
とは違うものです.

105) Instead the file specified is parsed by ecpg itself. So the contents of the specified file is included in the resulting C code. This way you are able to specify EXEC SQL commands in an include file.

指定されたファイルは ecpg がかわりに解析します. したがって指定されたファイルの内容は,処理結果の C のコードの中に含められます. この方法ではインクルードするファイルの中に EXEC SQL コマンドを指定することができます.

Connect 文

107) A connect statement looks like:

connect 文は以下のようになります:


108)
exec sql connect to connection target;
exec sql connect to 接続先;
109) It creates a connection to the specified database. これは指定されたデータベースへ接続します.

110) The connection target can be specified in the following ways:

接続先 は次のような方法でも指定できます.

データベース名 [@ サーバ][: ポート][as 接続名][user ユーザ名]

tcp:postgresql:// サーバ名 [: ポート][/ データベース名][as 接続名][user ユーザ名]

unix:postgresql:// サーバ [: ポート][/ データベース名][as 接続名][user ユーザ名]

文字変数[as 接続名][user ユーザ名]

文字列[as 接続名][user ユーザ名]

default

user

117) There are also different ways to specify the user name:

ユーザ名を指定するにも複数の方法があります:

ユーザ ID

ユーザ ID/パスワード

ユーザ ID identified by パスワード

ユーザ ID using パスワード

122) Finally the userid and the password. Each may be a constant text, a character variable or a chararcter string. ※ Each may be a 〜 a) constant text = exec sql 文にリテラルとしてあらわれる文字列 (?) ex) exec sql connect to postgres user postgres b) character string = "..." 式の文字列 (?) ex) exec sql connect to postgres user "postgres"

最後にユーザ ID とパスワード. それぞれは(ソース)テキスト,文字列定数,あるいは文字列のいずれかで指定します.

Disconnect 文

124) A disconnect statement looks loke:

disconnect 文は以下のようになります:


125)
exec sql disconnect [connection target];
exec sql disconnect [接続先];
126) It closes the connection to the specified database. 指定されたデータベースとの接続を閉じます.

127) The connection target can be specified in the following ways:

接続先 は以下のように指定します:

接続名

129) ↓以下三つは訳し忘れではありません

default

current

all

WARNING: FROM HERE ON THE TEXT IS OUTDATED! 注意:ここから先は古い内容です!

Open cursor 文 [1]

133) An open cursor statement looks like:

open cursor 文は以下のようになります:


134)
exec sql open cursor;
exec sql open カーソル;
135) and is ignore and not copied from the output. ※ ignore -> ignored(?) これは無視され,出力からコピーもされません.

Commit 文

137) A commit statement looks like

commit 文は以下のようになります:

exec sql commit;
138) and is translated on the output to これは次のように変換されます:
ECPGcommit(__LINE__);

Rollback 文

140) A rollback statement looks like

rollback 文は以下のようになります:

exec sql rollback;
141) and is translated on the output to これは次のように変換されます:
ECPGrollback(__LINE__);

その他の文

145) Other SQL statements are other statements that start with exec sql and ends with ;. Everything inbetween is treated as an SQL statement and parsed for variable substitution.

その他の SQL 文は exec sql で始まり, セミコロン(;)で終わる文です. 両者の間にあるものはすべて SQL 文として扱われ, 変数を置換するための構文解析がおこなわれます.

146) Variable substitution occur when a symbol starts with a colon (:). Then a variable with that name is looked for among the variables that were previously declared within a declare section and depending on the variable being for input or output the pointers to the variables are written to the output to allow for access by the function.

変数の置換はシンボルがコロン(:)で始まる場合に起きます. まず既に宣言セクションで宣言した変数の中からこの名前を持つ変数が探し出されます. そして変数が入力用/出力用のどちらであるかに従って変数へのポインタが出力ファイルに書き込まれ, 関数からのアクセスが可能になるのです.

147) For every variable that is part of the SQL request the function gets another ten arguments:

関数はさらに,SQL のリクエストの一部となる変数それぞれに対して十個の引数を取ります.

148)
The type as a special symbol.
A pointer to the value or a pointer to the pointer.
The size of the variable if it is a char or varchar.
Number of elements in the array (for array fetches).
The offset to the next element in the array (for array fetches)
The type of the indicator variable as a special symbol.
A pointer to the value of the indicator variable or a pointer to the pointer of the indicator variable.
0.
Number of elements in the indicator array (for array fetches).
The offset to the next element in the indicator array (for array fetches)

専用のシンボルで表した変数の型
値へのポインタ,またはそのポインタへのポインタ
変数のサイズ(char または varchar の場合)
配列の要素数(配列へのフェッチ用)
配列内の次の要素へのオフセット(配列へのフェッチ用)
専用のシンボルで表した標識変数 [2] の型
標識変数へのポインタ,またはそのポインタへのポインタ
0
標識変数配列の要素数(配列へのフェッチ用)
標識変数配列内の次の要素へのオフセット(配列へのフェッチ用)

完成例

150) Here is a complete example describing the output of the preprocessor of a file foo.pgc:

ここに挙げた完成例は,ファイル 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;
151) 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"
152) (the indentation in this manual is added for readability and not something that the preprocessor can do.) (なお,このマニュアルでは読みやすいようにインデントしましたが, プリプロセッサ自体はインデントをしません)

ライブラリ

154) The most important function in the library is the ECPGdo function. It takes a variable amount of arguments. Hopefully we will not run into machines with limits on the amount of variables that can be accepted by a vararg function. This could easily add up to 50 or so arguments.

ライブラリの中で最も重要な関数は ECPGdo です. この関数が取る引数の数は可変ですが, 幸いなことにこのような関数が受け取る変数の数に制限があるようなマシンに行き当たることはないでしょう. 50 やそこらの引数くらいまでなら平気です.

155) The arguments are:

引数は以下の通り:

行番号

157) This is a line number for the original line used in error messages only.

これは元ファイルの行番号でエラーメッセージにだけ使われます.

文字列

159) This is the SQL request that is to be issued. This request is modified by the input variables, i.e. the variables that where not known at compile time but are to be entered in the request. Where the variables should go the string contains ";".

これは発行される SQL リクエストです. このリクエストは入力変数,すなわち「コンパイル時には居所がわからないが, リクエストの中に加えられる予定の変数」によって加工されます. 変数が納められるのは ";" [3] を含む文字列です.

入力変数

161) As described in the section about the preprocessor every input variable gets ten arguments.

プリプロセッサに関するセクションで説明した通り, 個々の入力変数は十個の引数を取ります.

ECPGt_EOIT

162) An enum telling that there are no more input variables.

これ以上入力変数がないことを示す列挙型の値です.

出力変数

164) As described in the section about the preprocessor every input variable gets ten arguments. These variables are filled by the function. ※ input variable → output variable

プリプロセッサに関するセクションで説明した通り, 個々の出力変数は十個の引数を取ります. これらの変数は関数によって値が格納されます.

ECPGt_EORT

165) An enum telling that there are no more variables.

これ以上変数がないことを示す列挙型の値です.

166) All the SQL statements are performed in one transaction unless you issue a commit transaction. To get this auto-transaction going the first statement or the first after statement after a commit or rollback always begins a transaction. To disable this feature per default use the '-t' option on the commandline

commit transaction を発行しない限り, SQL 文はすべて単一のトランザクション内で実行されます. この自動トランザクション実行を実現するために,最初の文, または commit/rollback の後の最初の文は常にトランザクションを開始します. デフォルトによるこの機能を禁止するにはコマンドラインで '-t' オプションを使います.

167) To be completed: entries describing the other entries. ※どう訳したものか,よくわかりません.

他の事項の説明項目は未完です.

Notes

[1]

訳注:原文では Open cursor 文から Rollback 文までの説明が既に古くなっているとの コメントが入っています.

[2]

訳注:フィールドの値とは別に,フィールドが NULL かどうかを, あるいはフィールドの文字列がそれを格納する変数の領域より長いために, 切り捨てられた場合の情報を示すための変数 (indicator variable) です.

[3]

訳注:文意からすると ';' ではなく,'?' と思えます.