Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (日本語) » SQL Anywhere サーバ - プログラミング » SQL Anywhere データ・アクセス API » SQL Anywhere 外部関数 API » 外部関数のプロトタイプ

 

an_extfn_api 構造体

呼び出し元の SQL 環境と通信するために使用します。

構文
typedef struct an_extfn_api {
    short (SQL_CALLBACK *get_value)(
                void *          arg_handle,
                a_sql_uint32    arg_num,
                an_extfn_value *value
                );
    short (SQL_CALLBACK *get_piece)(
                void *          arg_handle,
                a_sql_uint32    arg_num,
                an_extfn_value *value,
                a_sql_uint32    offset
                );
    short (SQL_CALLBACK *set_value)(
                void *          arg_handle,
                a_sql_uint32    arg_num,
                an_extfn_value *value
                short           append
                );
    void (SQL_CALLBACK *set_cancel)(
                void *          arg_handle,
                void *          cancel_handle
                );
} an_extfn_api;
プロパティ
  • get_value   このコールバック関数を使用して、指定されたパラメータの値を取得します。次の例は、パラメータ 1 の値を取得します。
    result = extapi->get_value( arg_handle, 1, &arg )
    if( result == 0 || arg.data == NULL )
    {
        return; // no parameter or parameter is NULL
    }

  • get_piece   このコールバック関数を使用して、指定されたパラメータの値の次のチャンクを取得します (存在する場合)。次の例は、パラメータ 1 の残りの部分を取得します。
    cmd = (char *)malloc( arg.len.total_len + 1 );
    offset = 0;
    for( ; result != 0; )
    {
         if( arg.data == NULL ) break;
         memcpy( &cmd[offset], arg.data, arg.piece_len );
         offset += arg.piece_len;
         cmd[offset] = '\0';
         if( arg.piece_len == 0 ) break;
         result = extapi->get_piece( arg_handle, 1, &arg, offset );
    }

  • set_value   このコールバック関数を使用して、指定されたパラメータの値を設定します。次の例は、関数の RETURNS 句の戻り値 (パラメータ 0) を設定します。
    an_extfn_value      retval;
    int ret = -1;
    
    // set up the return value struct
    retval.type = DT_INT;
    retval.data = (void*) &ret;
    retval.piece_len = retval.len.total_len =
        (a_sql_uint32) sizeof( int );
    extapi->set_value( arg_handle, 0, &retval, 0 );

  • set_cancel   このコールバック関数を使用して、extfn_cancel メソッドによって設定できる変数へのポインタを確立します。次はその例です。
    short               canceled = 0;
    extapi->set_cancel( arg_handle, &canceled );

備考

an_extfn_api 構造体へのポインタは、呼び出し元から外部関数へ渡されます。次に例を示します。

extern "C" __declspec( dllexport )
void my_external_proc( an_extfn_api *extapi, void *arg_handle )
{
    short               result;
    short               canceled;
    an_extfn_value      arg;

    canceled = 0;
    extapi->set_cancel( arg_handle, &canceled );

    result = extapi->get_value( arg_handle, 1, &arg );
    if( canceled || result == 0 || arg.data == NULL )
    {
        return; // no parameter or parameter is NULL
    }
.
.
.
}

任意のコールバック関数を使用する場合、2 番目のパラメータとして外部関数に渡された引数ハンドルを戻す必要があります。

参照