Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.
用于从调用 SQL 环境访问参数数据。
typedef struct an_extfn_value { void * data; a_sql_uint32 piece_len; union { a_sql_uint32 total_len; a_sql_uint32 remain_len; } len; a_sql_data_type type; } an_extfn_value;
data 指向此参数数据的指针。
piece_len 参数本段的长度。其小于或等于 total_len。
total_len 参数的总长度。对于字符串,它表示字符串的长度且不包括空终止符。调用 get_value 回调函数后,即会设置此属性。调用 get_piece 回调函数后,此属性不再有效。
remain_len 当分段获取参数时,其为尚未获取的部分的长度。每次调用 get_piece 回调函数后,均会设置此属性。
type 指示参数的类型。它是嵌入式 SQL 数据类型之一,如 DT_INT、DT_FIXCHAR 或 DT_BINARY。请参见嵌入式 SQL 数据类型。
假设外部函数接口是使用以下 SQL 语句描述的。
CREATE FUNCTION mystring( IN instr LONG VARCHAR ) RETURNS LONG VARCHAR EXTERNAL NAME 'mystring@c:\\project\\mystring.dll';
以下代码段显示了如何访问类型为 an_extfn_value 的对象的属性。在本示例中,此函数 (mystring) 的输入参数 1 (instr) 应为 SQL LONGVARCHAR 字符串。
mystring
instr
an_extfn_value arg; result = extapi->get_value( arg_handle, 1, &arg ); if( result == 0 || arg.data == NULL ) { return; // no parameter or parameter is NULL } if( arg.type != DT_LONGVARCHAR ) { return; // unexpected type of parameter } 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 ); }