Changes data from one datatype to another.
int srv_convert (
SRV_PROC * srvproc,
int srctype,
void * src,
DBINT srclen,
int desttype,
void * dest,
DBINT destlen );
where
If desttype is SRVDECIMAL or SRVNUMERIC, the dest parameter must be a pointer to a DBNUMERIC or DBDECIMAL structure with the precision and scale fields of the structure already set to the desired values. You can use DEFAULTPRECISION to specify a default precision and DEFAULTSCALE to specify a default scale.
The length of the converted data, in bytes, if the datatype conversion succeeds. When srv_convert encounters a request for a conversion that it doesn't support, it calls the developer-supplied error handler (if any), sets a global error number, and returns FAIL.
Conversion to and from all Open Data Services datatypes is supported, except for conversion from SRVDATETIME or SRVDATETIME4 to these datatypes, and from these datatypes to SRVDATETIME or SRVDATETIME4:
The srv_willconvert function determines whether a particular conversion is allowed.
Converting to the approximate numeric datatypes SRVFLT4 or SRVFLT8 can result in some loss of precision. Converting from the approximate numeric datatypes SRVFLT4 or SRVFLT8 to SRVCHAR or SRVTEXT can also result in some loss of precision.
Converting to SRVFLTx, SRVINTx, SRVMONEY, SRVMONEY4, SRVDECIMAL, or SRVNUMERIC can result in overflow if the number is larger than the destination's maximum value, or in underflow if the number is smaller than the destination's minimum value. If overflow occurs when converting to SRVCHAR or SRVTEXT, the first character of the resulting value contains an asterisk (*) to indicate the error.
When converting SRVCHAR to SRVBINARY, srv_convert interprets SRVCHAR as hexadecimal, whether or not the string contains a leading 0. When converting SRVBINARY to SRVCHAR, srv_convert creates a hexadecimal string without a leading 0. In all other cases, a conversion to or from the SRVBINARY datatype is a straight bit-copy.
In certain cases, it can be useful to convert a datatype to itself. For example, converting SRVCHAR to SRVCHAR with a destlen of -1 adds a null terminator to a string.
The srv_convert function can fail for several reasons:
This entry | For information about |
---|---|
srv_describe | Describing a result row column |
srv_errhandle | Listing Open Data Services errors |
srv_setutype | Setting datatypes columns in rows |
srv_willconvert | Determining available datatype conversions |
Datatypes | Open Data Services datatypes |