Datatypes and capabilities

To send and receive 2-byte characters, the client specifies its preferred byte order during the login phase of the connection. Any necessary byte-swapping is performed on the server site.

The Open Client ct_capability() parameters are as follows:

To access 2-byte character data, Open Client and Open Server implements the following:

Setting the CS_DATAFMT parameter’s datatype to CS_UNICHAR_TYPE allows you to use existing API calls, such as ct_bind, ct_describe, ct_param, and so on.

CS_UNICHAR uses the format bitmask field of CS_DATAFMT to describe the destination format.

For example, in the Client-Library sample program, rpc.c, the BuildRpcCommand() function contains the section of code that describes the datatype:

...
strcpy (datafmt.name, “@charparam”);
datafmt.namelen =CS_NULLTERM;
datafmt.datatype = CS_CHAR_TYPE;
datafmt.maxlength = CS_MAX_CHAR;
datafmt.status = CS_RETURN;
datafmt.locale = NULL;
...

In this example from the uni_rpc.c sample program, the character type is defined as datafmt.datatype = CS_CHAR_TYPE. Use an ASCII text editor to edit the datafmt.datatype field:

...
strcpy (datafmt.name, “@charparam”);
datafmt.namelen =CS_NULLTERM;
datafmt.datatype = CS_UNICHAR_TYPE;
datafmt.maxlength = CS_MAX_CHAR;
datafmt.status = CS_RETURN;
datafmt.locale = NULL;
...

Samples are found in %SYBASE%\%SYBASE_OCS%\sample for Windows, and $SYBASE/$SYBASE_OCS/sample for UNIX.

Since CS_UNICHAR is a UTF-16 encoded Unicode character datatype that is stored in 2 bytes, the maximum length of CS_UNICHAR string parameter sent to the server is restricted to one-half the length of CS_CHAR, which is stored in 1-byte format.

Table 2-8 lists the CS_DATAFMT bitmask fields.

Table 2-8: CS_DATAFMT structure

Bitmask field

Description

CS_FMT_NULLTERM

The data is 2-byte Unicode null-terminated (0x0000).

CS_FMT_PADBLANK

The data is padded with 2-byte Unicode blanks to the full length of the destination variable (0x0020).

CS_FMT_PADNULL

The data is padded with 2-byte Unicode nulls to the full length of the destination variable (0x0000).

CS_FMT_UNUSED

No format information is provided.