用于与调用 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 使用此回调函数设置指定参数的值。以下示例为 FUNCTION 的 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 } . . . } |
每当使用上述的任意一个回调函数时,都必须传递回作为第二个参数传递到外部函数的参数句柄。
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |