バージョンごとのドキュメント一覧

GET DESCRIPTOR

GET DESCRIPTOR <refpurpose>get information from an SQL descriptor area</refpurpose> — SQL記述子領域から情報を入手します。

概要

GET DESCRIPTOR descriptor_name :cvariable = descriptor_header_item [, ... ]
GET DESCRIPTOR descriptor_name VALUE column_number :cvariable = descriptor_item [, ... ]

説明

<title>Description</title>

<command>GET DESCRIPTOR</command> retrieves information about a query result set from an SQL descriptor area and stores it into host variables. A descriptor area is typically populated using <command>FETCH</command> or <command>SELECT</command> before using this command to transfer the information into host language variables. GET DESCRIPTORはSQL記述子領域から問い合わせ結果セットに関する情報を取り出し、それをホスト変数に格納します。 記述子領域は通常、このコマンドを使用してホスト言語変数に情報を転送する前に、FETCHまたはSELECTを用いて値が投入されます。

This command has two forms: The first form retrieves descriptor <quote>header</quote> items, which apply to the result set in its entirety. One example is the row count. The second form, which requires the column number as additional parameter, retrieves information about a particular column. Examples are the column name and the actual column value. このコマンドには2つの構文があります。 1番目の構文では、そのまま結果セットに適用されている記述子のヘッダ項目を取り出します。 行数が1つの例です。 列番号を追加のパラメータとして必要とする2番目の構文では特定の列に関する情報を取り出します。 例えば、列名と列の実際の値です。

パラメータ

<title>Parameters</title>
descriptor_name #

A descriptor name. 記述子の名前です。

descriptor_header_item #

A token identifying which header information item to retrieve. Only <literal>COUNT</literal>, to get the number of columns in the result set, is currently supported. どのヘッダ情報を取り出すかを識別するトークンです。 結果セット内の列数を入手するCOUNTのみが現在サポートされています。

column_number #

The number of the column about which information is to be retrieved. The count starts at 1. 情報を取り出す列の番号です。 1から数えます。

descriptor_item #

A token identifying which item of information about a column to retrieve. See <xref linkend="ecpg-named-descriptors"/> for a list of supported items. どの列に関する情報を取り出すかを識別するトークンです。 サポートされる項目のリストについては36.7.1を参照してください。

cvariable #

A host variable that will receive the data retrieved from the descriptor area. 記述子領域から取り出したデータを受け取るホスト変数です。

<title>Examples</title>

An example to retrieve the number of columns in a result set: この例は結果セット内の列数を取り出します。

EXEC SQL GET DESCRIPTOR d :d_count = COUNT;

An example to retrieve a data length in the first column: この例は最初の列のデータ長を取り出します。

EXEC SQL GET DESCRIPTOR d VALUE 1 :d_returned_octet_length = RETURNED_OCTET_LENGTH;

An example to retrieve the data body of the second column as a string: この例は、2番目の列のデータ本体を文字列として取り出します。

EXEC SQL GET DESCRIPTOR d VALUE 2 :d_data = DATA;

Here is an example for a whole procedure of executing <literal>SELECT current_database();</literal> and showing the number of columns, the column data length, and the column data: 以下は、SELECT current_database();を実行し、列数、列のデータ長、列のデータを表示する手続き全体を示す例です。

int
main(void)
{
EXEC SQL BEGIN DECLARE SECTION;
    int  d_count;
    char d_data[1024];
    int  d_returned_octet_length;
EXEC SQL END DECLARE SECTION;

    EXEC SQL CONNECT TO testdb AS con1 USER testuser;
    EXEC SQL SELECT pg_catalog.set_config('search_path', '', false); EXEC SQL COMMIT;
    EXEC SQL ALLOCATE DESCRIPTOR d;


    /* Declare, open a cursor, and assign a descriptor to the cursor  */

    /* カーソルを宣言して開いて、記述子をそのカーソルに割り当てる */
    EXEC SQL DECLARE cur CURSOR FOR SELECT current_database();
    EXEC SQL OPEN cur;
    EXEC SQL FETCH NEXT FROM cur INTO SQL DESCRIPTOR d;


    /* Get a number of total columns */

    /* 全列数を得る */
    EXEC SQL GET DESCRIPTOR d :d_count = COUNT;
    printf("d_count                 = %d\n", d_count);


    /* Get length of a returned column */

    /* 返された列の長さを得る */
    EXEC SQL GET DESCRIPTOR d VALUE 1 :d_returned_octet_length = RETURNED_OCTET_LENGTH;
    printf("d_returned_octet_length = %d\n", d_returned_octet_length);


    /* Fetch the returned column as a string */

    /* 返された列を文字列として取得する */
    EXEC SQL GET DESCRIPTOR d VALUE 1 :d_data = DATA;
    printf("d_data                  = %s\n", d_data);


    /* Closing */

    /* 閉じる */
    EXEC SQL CLOSE cur;
    EXEC SQL COMMIT;

    EXEC SQL DEALLOCATE DESCRIPTOR d;
    EXEC SQL DISCONNECT ALL;

    return 0;
}

When the example is executed, the result will look like this: この例を実行すると、結果は以下のようになります。

d_count                 = 1
d_returned_octet_length = 6
d_data                  = testdb

互換性

<title>Compatibility</title>

<command>GET DESCRIPTOR</command> is specified in the SQL standard. GET DESCRIPTORは標準SQLで規定されています。

関連項目

<title>See Also</title> ALLOCATE DESCRIPTOR, SET DESCRIPTOR