ecpg の使い方

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 という名前です. インストールすると Postgresbin/ ディレクトリに置かれます.

ライブラリ

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.

ライブラリはいくつか「秘密の」メソッドを持っていますが, これが時として非常に役立つことがわかるはずです.

エラー処理

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:

発生する可能性のあるエラーのリストです:

-12, Out of memory in line %d.(メモリが足りません:行番号 %d.)

30) Does not normally occur. This is a sign that your virtual memory is exhausted.

通常は発生しません.これは仮想メモリを使い尽くしてしまったことを示すものです.

-200, Unsupported type %s on line %d. (%s はサポートされていない型です:行番号 %d.)

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.

通常は発生しません. これはライブラリの知らない何かをプリプロセッサが生成したことを示すものです. おそらく互換性のないバージョンのプリプロセッサとライブラリを使ったのでしょう.

-201, Too many arguments line %d. (引数が多すぎます:行番号 %d.)

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 リストの中のホスト変数の組を忘れてしまったのでしょう.

-202, Too few arguments line %d. (引数が足りません:行番号 %d.)

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 リストの中に余分なホスト変数の組があるのでしょう.

-203, Too many matches line %d. (マッチするものが多すぎます:行番号 %d.)

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 文が一意になるものではなかったのでしょう.

-204, Not correctly formatted int type: %s line %d. (正しくフォーマットされた int 型ではありません : %s :行番号 %d.)

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 を使います.

-205, Not correctly formatted unsigned type: %s line %d. (正しくフォーマットされた unsigned 型ではありません : %s :行番号 %d.)

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 を使います.

-206, Not correctly formatted floating point type: %s line %d. (正しくフォーマットされた浮動小数点型ではありません : %s :行番号 %d.)

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 を使います.

-207, Unable to convert %s to bool on line %d. (%s から論理値へ変換できません:行番号 %d.)

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' のいずれでもないことを意味します.

-208, Empty query line %d. (空の問い合わせ行です:行番号 %d.)

48) Postgres returned PGRES_EMPTY_QUERY, probably because the query indeed was empty.

Postgres が PGRES_EMPTY_QUERY を返しました. おそらく問い合わせが実際には空だったのでしょう.

-220, No such connection %s in line %d. (%s という接続はありません:行番号 %d.)

50) The program tries to access a connection that does not exist.

プログラムが存在しない接続にアクセスしようとしました.

-221, Not connected in line %d. (接続されていません:行番号 %d.)

52) The program tries to access a connection that does exist but is not open.

プログラムがアクセスしようとした接続は存在しますがオープンはされていません.

-230, Invalid statement name %s in line %d. (無効な文の名前です %s :行番号 %d)

54) The statement you are trying to use has not been prepared.

まだ準備 (prepare) していない文を使おうとしました.

-400, Postgres error: %s line %d. (Postgres のエラー %s :行番号 %d.)

56) Some Postgres error. The message contains the error message from the Postgres backend.

Postgres の何らかのエラーです. このメッセージには Postgres バックエンドからのエラーメッセージも含まれています.

-401, Error in transaction processing line %d. (トランザクション処理内のエラー:行番号 %d.)

58) Postgres signalled to us that we cannot start, commit or rollback the transaction.

トランザクションのコミット,あるいはロールバックを開始できないと Postgres が知らせてきました.

-402, connect: could not open database %s. (connect: データベース %s を開けません)

60) The connect to the database did not work.

データベースへの接続が動作しません.

100, Data not found line %d. (データが見つかりません:行番号 %d.)

62) This is a "normal" error that tells you that what you are quering cannot be found or we have gone through the cursor.

これは問い合わせをしたものが見つからない, あるいはカーソルが末端を通り過ぎたといった「普通の」エラーです.