13) This section describes how to use the egpc tool.
このセクションでは ecpg ツールの使い方を解説します.
15) The preprocessor is called ecpg. After installation it resides in the Postgres bin/ directory.
プリプロセッサは ecpg という名前です. インストールすると Postgres の bin/ ディレクトリに置かれます.
17) The ecpg library is called libecpg.a or libecpg.so. Additionally, the library uses the libpq library for communication to the Postgres server so you will have to link your program with -lecpg -lpq.
ecpg のライブラリは libecpg.a あるいは libecpg.so という名前です. 加えてこのライブラリは Postgres サーバとの通信に libpq ライブラリを使うので, プログラムのリンクで -lecpg -lpq を指定しなければなりません.
18) The library has some methods that are "hidden" but that could prove very useful sometime.
ライブラリはいくつか「秘密の」メソッドを持っていますが, これが時として非常に役立つことがわかるはずです.
19) ECPGdebug(int on, FILE *stream) turns on debug logging if called with the first argument non-zero. Debug logging is done on stream. Most SQL statement logs its arguments and result.
ECPGdebug(int on, FILE *stream) は第一引数を 0 以外にして呼び出すとデバッグ用ログの記録を開始します. このデバッグログは stream に対して出力されます. SQL 文のほとんどはログにその引数と結果を残します.
20) The most important one (ECPGdo) that is called on almost all SQL statements logs both its expanded string, i.e. the string with all the input variables inserted, and the result from the Postgres server. This can be very useful when searching for errors in your SQL statements.
ほぼすべての SQL 文で呼び出される最も重要なメソッド ECPGdo は,詳細な文字列, すなわち入力変数すべてが挿入されたものと,Postgres サーバからの結果の両方をログに取ります. これは SQL 文の間違いを探し出す際に大変役に立ちます.
ECPGstatus() 21) This method returns TRUE if we are connected to a database and FALSE if not. このメソッドはデータベースに接続されている場合に TRUE を, そうでなければ FALSE を返します.
23) To be able to detect errors from the Postgres server you include a line like
exec sql include sqlca;in the include section of your file. This will define a struct and a variable with the name sqlca as following:
Postgres からのエラーを検出できるようにするには,
exec sql include sqlca;のような行をソースファイルのインクルード部分に入れておきます. これは下のような sqlca という名前の構造体と変数を定義します.
struct sqlca { char sqlcaid[8]; long sqlabc; long sqlcode; struct { int sqlerrml; char sqlerrmc[70]; } sqlerrm; char sqlerrp[8]; long sqlerrd[6]; 24) /* 0: empty */ /* 1: empty */ /* 2: number of rows processed in an INSERT, UPDATE */ /* or DELETE statement */ /* 3: empty */ /* 4: empty */ /* 5: empty */ /* 0: 空 */ /* 1: 空 */ /* 2: INSERT, UPDATE, DELETE 文で処理された行数 */ /* 3: 空 */ /* 4: 空 */ /* 5: 空 */ char sqlwarn[8]; 25) /* 0: set to 'W' if at least one other is 'W' */ /* 1: if 'W' at least one character string */ /* value was truncated when it was */ /* stored into a host variable. */ /* 2: empty */ /* 3: empty */ /* 4: empty */ /* 5: empty */ /* 6: empty */ /* 7: empty */ /* 0: 他の要素が 'W' であれば 'W' がセットされます */ /* 1: 'W' であれば,ホスト変数に文字列を代入する時に */ /* 少なくともひとつの値が余分を切り落とされていま */ /* す */ /* 2: 空 */ /* 3: 空 */ /* 4: 空 */ /* 5: 空 */ /* 6: 空 */ /* 7: 空 */ char sqlext[8]; } sqlca;
26) If an error occured in the last SQL statement then sqlca.sqlcode will be non-zero. If sqlca.sqlcode is less that 0 then this is some kind of serious error, like the database definition does not match the query given. If it is bigger than 0 then this is a normal error like the table did not contain the requested row. ※ if sqlca.sqlcode is less that 0 then → ..less than 0 then..
直前の SQL 文でエラーが発生すると sqlca.sqlcode が 0 以外の値になります. もし sqlca.sqlcode が 0 より小さな値であれば, データベースの定義が与えられた問い合わせと合致しないといった何らかの深刻なエラーです. 0 よりも大きな値であれば, テーブルが要求した行を含んでいないなどの普通のエラーです.
27) sqlca.sqlerrm.sqlerrmc will contain a string that describes the error. The string ends with the line number in the source file.
sqlca.sqlerrm.sqlerrmc にはエラーを説明する文字列が含まれます. 文字列はソースファイル中の該当行番号で終わります.
28) List of errors that can occur:
発生する可能性のあるエラーのリストです:
30) Does not normally occur. This is a sign that your virtual memory is exhausted.
通常は発生しません.これは仮想メモリを使い尽くしてしまったことを示すものです.
32) Does not normally occur. This is a sign that the preprocessor has generated something that the library does not know about. Perhaps you are running incompatible versions of the preprocessor and the library.
通常は発生しません. これはライブラリの知らない何かをプリプロセッサが生成したことを示すものです. おそらく互換性のないバージョンのプリプロセッサとライブラリを使ったのでしょう.
34) This means that Postgres has returned more arguments than we have matching variables. Perhaps you have forgotten a couple of the host variables in the INTO :var1,:var2-list. ※ matching variables を次項にあわせてホスト変数と訳出
これは用意したホスト変数よりも多くの引数を Postgres が返したことを意味します. おそらく INTO :var1,:var2 リストの中のホスト変数の組を忘れてしまったのでしょう.
36) This means that Postgres has returned fewer arguments than we have host variables. Perhaps you have too many host variables in the INTO :var1,:var2-list.
これは用意したホスト変数よりも少ない引数を Postgres が返したことを意味します. おそらく INTO :var1,:var2 リストの中に余分なホスト変数の組があるのでしょう.
38) This means that the query has returned several lines but the variables specified are no arrays. The SELECT you made probably was not unique.
これは問い合わせが複数行を返したが,指定した変数が配列ではないことを意味します. たぶん,発行した SELECT 文が一意になるものではなかったのでしょう.
40) This means that the host variable is of an int type and the field in the Postgres database is of another type and contains a value that cannot be interpreted as an int. The library uses strtol for this conversion.
これはホスト変数の型が int であるにもかかわらず, Postgres データベースのフィールドが他の型であり, int として解釈できない値が含まれていることを意味します. ライブラリはこの変換に strtol を使います.
42) This means that the host variable is of an unsigned int type and the field in the Postgres database is of another type and contains a value that cannot be interpreted as an unsigned int. The library uses strtoul for this conversion.
これはホスト変数の型が unsigned int であるにもかかわらず, Postgres データベースのフィールドが他の型であり, unsigned int として解釈できない値が含まれていることを意味します. ライブラリはこの変換に strtoul を使います.
44) This means that the host variable is of a float type and the field in the Postgres database is of another type and contains a value that cannot be interpreted as an float. The library uses strtod for this conversion.
これはホスト変数の型が float であるにもかかわらず, Postgres データベースのフィールドが他の型であり, float として解釈できない値が含まれていることを意味します. ライブラリはこの変換に strtod を使います.
46) This means that the host variable is of a bool type and the field in the Postgres database is neither 't' nor 'f'.
これはホスト変数の型が bool であるにもかかわらず, Postgres データベースのフィールドが 't' と 'f' のいずれでもないことを意味します.
48) Postgres returned PGRES_EMPTY_QUERY, probably because the query indeed was empty.
Postgres が PGRES_EMPTY_QUERY を返しました. おそらく問い合わせが実際には空だったのでしょう.
50) The program tries to access a connection that does not exist.
プログラムが存在しない接続にアクセスしようとしました.
52) The program tries to access a connection that does exist but is not open.
プログラムがアクセスしようとした接続は存在しますがオープンはされていません.
54) The statement you are trying to use has not been prepared.
まだ準備 (prepare) していない文を使おうとしました.
56) Some Postgres error. The message contains the error message from the Postgres backend.
Postgres の何らかのエラーです. このメッセージには Postgres バックエンドからのエラーメッセージも含まれています.
58) Postgres signalled to us that we cannot start, commit or rollback the transaction.
トランザクションのコミット,あるいはロールバックを開始できないと Postgres が知らせてきました.
60) The connect to the database did not work.
データベースへの接続が動作しません.
62) This is a "normal" error that tells you that what you are quering cannot be found or we have gone through the cursor.
これは問い合わせをしたものが見つからない, あるいはカーソルが末端を通り過ぎたといった「普通の」エラーです.