Sybase Technical Library - Product Manuals Home
[Search Forms] [Previous Section with Hits] [Next Section with Hits] [Clear Search] Expand Search

text and image data
handling [Table of Contents] Using
the runtime configuration file

Open Client Client-Library/C Reference Manual

[-] Chapter 2 Topics
[-] Types

Types

Client-Library supports a wide range of datatypes. These datatypes are shared with Open Client CS-Library and Server-Library. In most cases, they correspond directly to Adaptive Server datatypes.

Table 2-32 lists Open Client/Server type constants, their corresponding C datatypes, and their corresponding Adaptive Server, if any.

Following Table 2-32 is a list of Open Client routines that are useful in manipulating datatypes and more detailed information about each datatype.

For additional information about datatypes, see Chapter 3, "Using Open Client/Server Datatypes," in the Open Client Client-Library/C Programmer's Guide.

Datatype summary

The following table lists Open Client/Server type constants, their corresponding C datatypes, and their corresponding Adaptive Server datatypes, if any:

Datatype summary

Type category

Open Client/Server type constant

Description

Corresponding C datatype

Corresponding server datatype

Binary types

CS_BINARY_TYPE

Binary type

CS_BINARY

binary,varbinary

CS_LONGBINARY_TYPE

Long binary type

CS_LONGBINARY

None

CS_VARBINARY_TYPE

Variable-length binary type

CS_VARBINARY

None

Bit types

CS_BIT_TYPE

Bit type

CS_BIT

bit

Character types

CS_CHAR_TYPE

Character type

CS_CHAR

char,varchar

CS_LONGCHAR_TYPE

Long character type

CS_LONGCHAR

None

CS_VARCHAR_TYPE

Variable-length character type

CS_VARCHAR

None

CS_UNICHAR_TYPE

Fixed-length or variable-length character type

CS_UNICHAR

unichar

univarchar

Datetime types

CS_DATETIME_TYPE

8-byte datetime type

CS_DATETIME

datetime

CS_DATETIME4_TYPE

4-byte datetime type

CS_DATETIME4

smalldatetime

Numeric types

CS_TINYINT_TYPE

1-byte unsigned integer type

CS_TINYINT

tinyint

CS_SMALLINT_TYPE

2-byte integer type

CS_SMALLINT

smallint

CS_INT_TYPE

4-byte integer type

CS_INT

int

CS_DECIMAL_TYPE

Decimal type

CS_DECIMAL

decimal

CS_NUMERIC_TYPE

Numeric type

CS_NUMERIC

numeric

CS_FLOAT_TYPE

8-byte float type

CS_FLOAT

float

CS_REAL_TYPE

4-byte float type

CS_REAL

real

Money types

CS_MONEY_TYPE

8-byte money type

CS_MONEY

money

CS_MONEY4_TYPE

4-byte money type

CS_MONEY4

smallmoney

Text and image types

CS_TEXT_TYPE

Text type

CS_TEXT

text

CS_IMAGE_TYPE

Image type

CS_IMAGE

image

Routines that manipulate datatypes

Open Client CS-Library provides several routines that are useful for manipulating datatypes. They include:

These routines are documented in the Open Client and Open Server Common Libraries Reference Manual.

Open Client datatypes

This section describes the datatypes in Open Client, and provides definitions for the datatypes.

Binary types

Open Client has three binary types, CS_BINARY, CS_LONGBINARY, and CS_VARBINARY.

Bit types

Open Client supports a single bit type, CS_BIT. This type is intended to hold server bit (or boolean) values of 0 or 1. When converting other types to bit, all non-zero values are converted to 1:

typedef unsigned char    CS_BIT;    

Character types

Open Client has three character types, CS_CHAR, CS_LONGCHAR, and CS_VARCHAR:

Datetime types

Open Client supports two datetime types, CS_DATETIME and CS_DATETIME4. These datatypes are intended to hold 8-byte and 4-byte datetime values, respectively.

An Open Client application uses the CS-Library routine cs_dt_crack to extract date parts (year, month, day, etc.) from a datetime structure.

Numeric types

Open Client supports a wide range of numeric types.

Money types

Open Client supports two money types, CS_MONEY and CS_MONEY4. These datatypes are intended to hold 8-byte and 4-byte money values, respectively.

text and image types

Open Client supports a text datatype, CS_TEXT, and an image datatype, CS_IMAGE.

Open Client user-defined datatypes

An application that needs to use a datatype that is not included in the standard Open Client type set may create a user-defined datatype.

A Client-Library application creates a user-defined type by declaring it:

typedef char    CODE_NAME;

The Open Client routines ct_bind and cs_set_convert use integer symbolic constants to identify datatypes, so it is often convenient for an application to declare a type constant for a user-defined type. User-defined types must be defined as greater than or equal to CS_USERTYPE:

#define CODE_NAME_TYPE    (CS_USERTYPE + 2)

Once a user-defined type has been created, an application:

After conversion routines are installed, an application binds server results to a user-defined type:

mydatafmt.datatype = CODE_NAME_TYPE;
 ct_bind(cmd, 1, &mydatafmt, mycodename, NULL,
     NULL);

Custom conversion routines are called transparently, whenever required, by ct_fetch (following a call to ct_bind specifying the conversion) and cs_convert.

Do not confuse Open Client user-defined types with Adaptive Server user-defined types. Open Client user-defined types are C-language types, declared within an application. Adaptive Server user-defined types are database column datatypes, created using the system stored procedure sp_addtype.


text and image data
handling [Table of Contents] Using
the runtime configuration file