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.
Following are the Open Client ct_capability() parameters:
CS_DATA_UCHAR is a request sent to the server to determine whether the server supports 2-byte characters.
CS_DATA_NOUCHAR is a parameter sent from the client to tell the server not to support unichar for this specific connection.
To access 2-byte character data, Open Client and Open Server implements:
CS_UNICHAR – a datatype.
CS_UNICHAR_TYPE – a datatype constant to identify the data’s datatype.
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
to:
...
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 in $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 3-1 lists the CS_DATAFMT bitmask fields.
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. |