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.

    PGPORT �� Postgres �Хå�����ɤ��̿����뤿��Υǥե���ȥݡ��ȡ��ޤ��ϥ�������� 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.

    PGREALM �� Postgres �ȶ��˻Ȥ� Kerberos �� realm ����������Τ�ΤȰۤʤ���ˡ����� realm �����ꤷ�ޤ��� PGREALM �����ꤵ���ȡ� Postgres ���ץꥱ�����������ꤵ�줿 realm �Υ����С���������Ω���������åȥե������Ȥ��� ��������Υ����åȥե�����ȶ��礷�ʤ��褦�ˤ��ޤ��� ���δĶ��ѿ��ϥХå�����ɤ� Kerberos �ˤ��ǧ�ڤ����򤷤����ˤΤ߻Ȥ��ޤ���

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

    PGOPTIONS �� Postgres �Хå�����ɤ��Ф����ɲä����󥿥��४�ץ��������ꤷ�ޤ���

  • 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.

�����δĶ��ѿ����Ф��������������ͤ˴ؤ��Ƥ� SQL �� SET ���ޥ�ɤ򻲾Ȥ��Ƥ���������

Notes

[1]

�������ºݤˤϡֻ��ĤΥ���ץ�פϤ��Υɥ�����Ȥ˴ޤޤ�Ƥ��ޤ���