cs_will_convert

Description

Indicates whether a specific datatype conversion is available in the Client/Server libraries.

Syntax

CS_RETCODE cs_will_convert(context, srctype, desttype,
                result)
 
 CS_CONTEXT     *context;
 CS_INT                srctype;
 CS_INT                desttype;
 CS_BOOL            *result;

Parameters

context

A pointer to a CS_CONTEXT structure.

srctype

A symbolic constant representing the datatype of the source data (for example, CS_BYTE_TYPE, CS_CHAR_TYPE, and so forth).

desttype

A symbolic constant representing the datatype of the destination data.

result

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.

Returns

cs_will_convert returns:

Returns

Indicates

CS_SUCCEED

The routine completed successfully.

CS_FAIL

The routine failed.

Examples

Example 1

/*
 ** 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;
 }

Usage


Datatype conversion chart

A chart listing the datatype conversions that cs_convert supports is included on the manual page for cs_convert. (See Table 2-3.)

See also

cs_convert, cs_set_convert, cs_setnull