Chapter 17. libpq C++ バインディング

Table of Contents
制御と初期化
libpq++ のクラス
データベース接続関数
問い合わせ実行関数
非同期通知
COPY コマンドに関連した関数
注意点

2) libpq++ is the C++ API to Postgres. libpq++ is a set of classes which allow client programs to connect to the Postgres backend server. These connections come in two forms: a Database Class and a Large Object class.

libpq++Postgres のための C++ API で,Postgres バックエンドサーバへの接続手段をクライアントプログラムに与えるクラスの集合です. このバックエンドへの接続は二つの形態を取ります. ひとつは「データベースクラス」,もうひとつは「ラージオブジェクトクラス」です.

3) The Database Class is intended for manipulating a database. You can send all sorts of SQL queries to the Postgres backend server and retrieve the responses of the server.

「データベースクラス」の目的はデータベースの操作です. あらゆる種類の SQL の問い合わせを Postgres バックエンドサーバへ送信し,そしてサーバの応答を取り出すことができます.

4) The Large Object Class is intended for manipulating a large object in a database. Although a Large Object instance can send normal queries to the Postgres backend server it is only intended for simple queries that do not return any data. A large object should be seen as a file stream. In the future it should behave much like the C++ file streams cin, cout and cerr.

「ラージオブジェクトクラス」の目的はデータベース内のラージオブジェクトの操作です. ラージオブジェクトクラスのインスタンスも,Postgres バックエンドサーバへ通常の問い合わせを送ることはできます. しかしこれは,何もデータを返さない簡単な問い合わせをすることだけが目的です. ラージオブジェクト自体はファイルストリームのように見えるべきものなので, いずれは C++ のファイルストリーム, cin, cout および cerr とほぼ同じような動作になるはずです.

5) This chapter is based on the documentation for the libpq C library. Three short programs are listed at the end of this section as examples of libpq++ programming (though not necessarily of good programming). There are several examples of libpq++ applications in src/libpq++/examples, including the source code for the three examples in this chapter. ※サンプルのディレクトリを修正

この章は C ライブラリ libpq のドキュメントをベースにしています. このセクションの最後に libpq++ プログラミングの例として, 三つの短いプログラムを載せておきました. (必ずしもいいプログラム例とは言えませんが) また libpq++ アプリケーションの例として,いくつか src/interfaces/libpq++/examples に収録しています. この中には本章のサンプル三つも含まれています. [1]

制御と初期化

環境変数

8) The following environment variables can be used to set up default values for an environment and to avoid hard-coding database names into an application program: ※このセクションはほぼ libpq.sgml と同一文章です

以下の環境変数は動作環境のデフォルト値を設定し, システムデフォルトのデータベース名がアプリケーションプログラムに影響することを防ぎます.

Note: 9) Refer to the libpq for a complete list of available connection options.

使用できる接続オプションの全リストは libpq を参照して下さい.

10) The following environment variables can be used to select default connection parameter values, which will be used by PQconnectdb or PQsetdbLogin if no value is directly specified by the calling code. These are useful to avoid hard-coding database names into simple application programs.

PQconnection または PQsetdbLogin を呼び出すプログラムが,接続パラメータの値を直接指定しなかった場合, PQconnection と PQsetdbLogin は以下の環境変数を使って接続パラメータのデフォルト値を決定します. システムデフォルトのデータベース名が簡単なアプリケーションプログラムに影響することを防ぐのに便利です.

Note: 11) libpq++ uses only environment variables or PQconnect db conninfo style strings.

libpq++ が使うのは環境変数, あるいは PQconnect の conninfo 形式の文字列のみです.

  • 12) PGHOST sets the default server name. If a non-zero-length string is specified, TCP/IP communication is used. Without a host name, libpq will connect using a local Unix domain socket.

    PGHOST はデフォルトサーバ名を設定します. 長さが 0 でない文字列を設定した場合は TCP/IP による接続が使われます. ホスト名がない場合,libpq はローカルの UNIX ドメインソケットを使って接続します.

  • 13) PGPORT sets the default port or local Unix domain socket file extension for communicating with the Postgres backend.

    PGPORTPostgres バックエンドと通信するためのデフォルトポート,またはローカルの UNIX ドメインソケットファイルの拡張子を設定します.

  • 14) PGDATABASE sets the default Postgres database name.

    PGDATABASE はデフォルトの Postgres データベース名を設定します.

  • 15) PGUSER sets the username used to connect to the database and for authentication.

    PGUSER はデータベースへの接続と認証に使われるユーザ名を設定します.

  • 16) PGPASSWORD sets the password used if the backend demands password authentication.

    PGPASSWORD はバックエンドがパスワード認証を要求した場合に 使われるパスワードを設定します.

  • 17) PGREALM sets the Kerberos realm to use with Postgres, if it is different from the local realm. If PGREALM is set, Postgres applications will attempt authentication with servers for this realm and use separate ticket files to avoid conflicts with local ticket files. This environment variable is only used if Kerberos authentication is selected by the backend.

    PGREALMPostgres と共に使う Kerberos の realm がローカルのものと異なる場合に,その realm を設定します. PGREALM が設定されると, Postgres アプリケーションは設定された realm のサーバ,そして独立したチケットファイルを使い, ローカルのチケットファイルと競合しないようにします. この環境変数はバックエンドが Kerberos による認証を選択した場合にのみ使われます.

  • 18) PGOPTIONS sets additional runtime options for the Postgres backend.

    PGOPTIONSPostgres バックエンドに対して追加するランタイムオプションを設定します.

  • 19) PGTTY sets the file or tty on which debugging messages from the backend server are displayed.

    PGTTY はバックエンドサーバのデバッグメッセージを出力する ファイル,あるいは tty を設定します.

20) The following environment variables can be used to specify user-level default behavior for every Postgres session:

以下の環境変数は個々の Postgres とのセッションにおける,ユーザレベルの デフォルト動作を設定するのに使います.

  • 21) PGDATESTYLE sets the default style of date/time representation.

    PGDATESTYLE はデフォルトの日付表示スタイルを設定します.

  • 22) PGTZ sets the default time zone.

    PGTZ はデフォルトのタイムゾーンを設定します.

23) The following environment variables can be used to specify default internal behavior for every Postgres session:

以下の環境変数は個々の Postgres とのセッションにおける, デフォルトの内部動作を設定するのに使います.

  • 24) PGGEQO sets the default mode for the genetic optimizer.

    PGGEQO は遺伝的アルゴリズムによるオプティマイザの 動作モードを設定します.

  • 25) PGRPLANS sets the default mode to allow or disable right-sided plans in the optimizer.

    PGRPLANS はオプティマイザにおける右優先 プランニングをデフォルトで使用するかどうかを設定します.

  • 26) PGCOSTHEAP sets the default cost for heap searches for the optimizer.

    PGCOSTHEAP はオプティマイザに対して ヒープサーチのデフォルトコストを設定します.

  • 27) PGCOSTINDEX sets the default cost for indexed searches for the optimizer.

    PGCOSTINDEX はオプティマイザに対して インデックスサーチのデフォルトコストを設定します.

28) Refer to the SET SQL command for information on correct values for these environment variables.

これらの環境変数に対する正しい設定値に関しては SQLSET コマンドを参照してください.

Notes

[1]

訳注:実際には「三つのサンプル」はこのドキュメントに含まれていません