Indicates whether a specific datatype conversion is available in the Client/Server libraries.
CS_RETCODE cs_will_convert(context, srctype, desttype, result) CS_CONTEXT *context; CS_INT srctype; CS_INT desttype; CS_BOOL *result;
A pointer to a CS_CONTEXT structure.
A symbolic constant representing the datatype of the source data (for example, CS_BYTE_TYPE, CS_CHAR_TYPE, and so forth).
A symbolic constant representing the datatype of the destination data.
A pointer to a boolean variable. cs_will_convert sets *result to CS_TRUE if the datatype conversion is supported and CS_FALSE if the datatype conversion is not supported.
cs_will_convert returns:
Returns |
Indicates |
---|---|
CS_SUCCEED |
The routine completed successfully. |
CS_FAIL |
The routine failed. |
/*
** ex_display_column()
*/
CS_RETCODE CS_PUBLIC
ex_display_column(context, colfmt, data, datalength,
indicator)
CS_CONTEXT *context;
CS_DATAFMT *colfmt;
CS_VOID *data;
CS_INT datalength;
CS_SMALLINT indicator;
{
char *null = "NULL";
char *nc = "NO CONVERT";
char *cf = "CONVERT FAILED";
CS_DATAFMT srcfmt;
CS_DATAFMT destfmt;
CS_INT olen;
CS_CHAR wbuf[MAX_CHAR_BUF];
CS_BOOL res;
CS_INT i;
CS_INT disp_len;
if (indicator == CS_NULLDATA)
{
olen = strlen(null);
strcpy(wbuf, null);
}
else
{
cs_will_convert(context, colfmt->datatype,
CS_CHAR_TYPE, &res);
if (res != CS_TRUE)
{
olen = strlen(nc);
strcpy(wbuf, nc);
}
else
{
srcfmt.datatype = colfmt->datatype;
srcfmt.format = colfmt->format;
srcfmt.locale = colfmt->locale;
srcfmt.maxlength = datalength;
destfmt.maxlength = MAX_CHAR_BUF;
destfmt.datatype = CS_CHAR_TYPE;
destfmt.format = CS_FMT_NULLTERM;
destfmt.locale = NULL;
if (cs_convert(context, &srcfmt, data,
&destfmt, wbuf, &olen) != CS_SUCCEED)
{
olen = strlen(cf);
strcpy(wbuf, cf);
}
else
{
/*
** output length include null
** termination
*/
olen -= 1;
}
}
}
fprintf(stdout, "%s", wbuf);
disp_len = ex_display_dlen(colfmt);
for (i = 0; i < (disp_len - olen); i++)
{
fputc(' ', stdout);
}
return CS_SUCCEED;
}
cs_will_convert allows an application to determine whether cs_convert or ct_bind/ct_fetch are capable of performing a specific conversion. When cs_convert is called to perform a conversion that it does not support, it returns CS_FAIL and generates a CS-Library error.
cs_convert can convert between standard and user-defined datatypes. To enable these types of conversions, an application must install custom conversion routines through cs_set_convert. If a custom routine is supplied for a conversion, cs_will_convert indicates that the conversion is supported.
A chart listing the datatype conversions that cs_convert supports is included on the manual page for cs_convert. (See Figure 2-1.)