The following SQL data types can be passed to an external library:
SQL data type | sqldef.h | C type |
---|---|---|
CHAR | DT_FIXCHAR | Character data, with a specified length |
VARCHAR | DT_VARCHAR | Character data, with a specified length |
LONG VARCHAR, TEXT | DT_LONGVARCHAR | Character data, with a specified length |
UNIQUEIDENTIFIERSTR | DT_FIXCHAR | Character data, with a specified length |
XML | DT_LONGVARCHAR | Character data, with a specified length |
NCHAR | DT_NFIXCHAR | UTF-8 character data, with a specified length |
NVARCHAR | DT_NVARCHAR | UTF-8 character data, with a specified length |
LONG NVARCHAR, NTEXT | DT_LONGNVARCHAR | UTF-8 character data, with a specified length |
UNIQUEIDENTIFIER | DT_BINARY | Binary data, 16 bytes long |
BINARY | DT_BINARY | Binary data, with a specified length |
VARBINARY | DT_BINARY | Binary data, with a specified length |
LONG BINARY | DT_LONGBINARY | Binary data, with a specified length |
TINYINT | DT_TINYINT | 1-byte integer |
[ UNSIGNED ] SMALLINT | DT_SMALLINT, DT_UNSSMALLINT | [ Unsigned ] 2-byte integer |
[ UNSIGNED ] INT | DT_INT, DT_UNSINT | [ Unsigned ] 4-byte integer |
[ UNSIGNED ] BIGINT | DT_BIGINT, DT_UNSBIGINT | [ Unsigned ] 8-byte integer |
REAL, FLOAT(1-24) | DT_FLOAT | Single-precision floating-point number |
DOUBLE, FLOAT(25-53) | DT_DOUBLE | Double-precision floating-point number |
You cannot use any of the date or time data types, and you cannot use the DECIMAL or NUMERIC data types (including the money types).
To provide values for INOUT or OUT parameters, use the set_value function. To read IN and INOUT parameters, use the get_value function.
After a call to get_value, the type field of the an_extfn_value structure can be used to obtain data type information for the parameter. The following sample code fragment shows how to identify the type of the parameter.
an_extfn_value arg; a_sql_data_type data_type; extapi->get_value( arg_handle, 1, &arg ); data_type = arg.type & DT_TYPES; switch( data_type ) { case DT_FIXCHAR: case DT_VARCHAR: case DT_LONGVARCHAR: break; default: return; } |
For more information about data types, see Host variables in embedded SQL.
The UTF-8 data types such as NCHAR, NVARCHAR, LONG NVARCHAR and NTEXT as passed as UTF-8 encoded strings. A function such as the Windows MultiByteToWideChar function can be used to convert a UTF-8 string to a wide-character (Unicode) string.
You can pass NULL as a valid value for all arguments. Functions in external libraries can supply NULL as a return value for any data type.
To set a return value in an external function, call the set_value function with an arg_num parameter value of 0. If set_value is not called with arg_num set to 0, the function result is NULL.
It is also important to set the data type of a return value for a stored function call. The following code fragment shows how to set the return data type.
an_extfn_value retval; retval.type = DT_LONGVARCHAR; retval.data = result; retval.piece_len = retval.len.total_len = (a_sql_uint32) strlen( result ); extapi->set_value( arg_handle, 0, &retval, 0 ); |
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |