A client application can request cancellation of a command that is still being processed by the server, using the functions described in this section. 本節で説明する関数を使用して、クライアントアプリケーションはサーバで処理中のコマンドをキャンセルする要求を行うことができます。
PQgetCancel
#Creates a data structure containing the information needed to cancel a command issued through a particular database connection. 特定のデータベース接続を通して発行されたコマンドをキャンセルするために必要な情報を持つデータ構造を作成します。
PGcancel *PQgetCancel(PGconn *conn);
<xref linkend="libpq-PQgetCancel"/> creates a
<structname>PGcancel</structname><indexterm><primary>PGcancel</primary></indexterm> object
given a <structname>PGconn</structname> connection object. It will return
<symbol>NULL</symbol> if the given <parameter>conn</parameter> is <symbol>NULL</symbol> or an invalid
connection. The <structname>PGcancel</structname> object is an opaque
structure that is not meant to be accessed directly by the
application; it can only be passed to <xref linkend="libpq-PQcancel"/>
or <xref linkend="libpq-PQfreeCancel"/>.
PQgetCancel
は、与えられたPGconn
接続オブジェクトのPGcancel
オブジェクトを作成します。
与えられたconn
がNULL
もしくは無効な接続であった場合、NULL
が返されます。
PGcancel
オブジェクトは不透明な構造体であり、アプリケーションから直接アクセスすることができません。
これはPQcancel
もしくはPQfreeCancel
に渡すことしかできません。
PQfreeCancel
#
Frees a data structure created by <xref linkend="libpq-PQgetCancel"/>.
PQgetCancel
で作成されたデータ構造を解放します。
void PQfreeCancel(PGcancel *cancel);
<xref linkend="libpq-PQfreeCancel"/> frees a data object previously created
by <xref linkend="libpq-PQgetCancel"/>.
PQfreeCancel
は事前にPQgetCancel
で作成されたデータオブジェクトを解放します。
PQcancel
#Requests that the server abandon processing of the current command. サーバに現在のコマンドの廃棄処理を要求します。
int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize);
The return value is 1 if the cancel request was successfully
dispatched and 0 if not. If not, <parameter>errbuf</parameter> is filled
with an explanatory error message. <parameter>errbuf</parameter>
must be a char array of size <parameter>errbufsize</parameter> (the
recommended size is 256 bytes).
キャンセル要求の受け入れが成功すれば1を、そうでなければ0を返します。
失敗した場合、errbuf
にそれを説明するエラーメッセージが収納されます。
errbuf
はerrbufsize
サイズの文字配列でなければなりません。
(推奨サイズは256バイトです。)
Successful dispatch is no guarantee that the request will have any effect, however. If the cancellation is effective, the current command will terminate early and return an error result. If the cancellation fails (say, because the server was already done processing the command), then there will be no visible result at all. しかし、要求の受け入れが成功したとしても、その要求の効果が出ることは全く保証していません。 もしキャンセル操作が有効であれば、現在のコマンドは間もなく中断され、エラーが結果として返ります。 キャンセル操作に失敗した場合(例えばバックエンドがすでにコマンド処理を終了していたため)、目に見える結果は何も出てこなくなります。
<xref linkend="libpq-PQcancel"/> can safely be invoked from a signal
handler, if the <parameter>errbuf</parameter> is a local variable in the
signal handler. The <structname>PGcancel</structname> object is read-only
as far as <xref linkend="libpq-PQcancel"/> is concerned, so it can
also be invoked from a thread that is separate from the one
manipulating the <structname>PGconn</structname> object.
errbuf
がシグナルハンドラ内のローカル変数であれば、PQcancel
はシグナルハンドラから起動しても問題ありません。
PQcancel
の実行中、PGcancel
は読み取りのみです。
従って、PGconn
オブジェクトを操作するスレッドと別のスレッドからこの関数を呼び出すこともできます。
PQrequestCancel
#
<xref linkend="libpq-PQrequestCancel"/> is a deprecated variant of
<xref linkend="libpq-PQcancel"/>.
PQrequestCancel
はPQcancel
の廃止予定の変形版です。
int PQrequestCancel(PGconn *conn);
Requests that the server abandon processing of the current
command. It operates directly on the
<structname>PGconn</structname> object, and in case of failure stores the
error message in the <structname>PGconn</structname> object (whence it can
be retrieved by <xref linkend="libpq-PQerrorMessage"/>). Although
the functionality is the same, this approach is not safe within
multiple-thread programs or signal handlers, since it is possible
that overwriting the <structname>PGconn</structname>'s error message will
mess up the operation currently in progress on the connection.
サーバに現在のコマンドの廃棄処理を要求します。
これはPGconn
オブジェクトを直接扱い、また、失敗した場合エラーメッセージはPGconn
オブジェクト内に収納されます。
(PQerrorMessage
により取り出すことができます。)
機能的には同一ですが、この方法は複数スレッドプログラムやシグナルハンドラでは安全ではありません。PGconn
のエラーメッセージが上書きされることにより、その接続で現在進行中の操作を台無しにする可能性があるからです。