![]() | ![]() |
Home |
|
|
Open Client Client-Library/C Reference Manual |
|
| Chapter 2 Topics |
|
| Types |
|
| Open Client datatypes |
This section describes the datatypes in Open Client, and provides definitions for the datatypes.
Binary typesOpen Client has three binary types, CS_BINARY, CS_LONGBINARY, and CS_VARBINARY.
CS_BINARY corresponds to the Adaptive Server types binary and varbinary. That is, Client-Library interprets both the server binary and varbinary types as CS_BINARY. For example, ct_describe returns CS_BINARY_TYPE when describing a result column that has the server datatype varbinary.
CS_BINARY is defined as:
typedef unsigned char CS_BINARY;
Warning!
CS_LONGBINARY and CS_VARBINARY do not correspond to any SQL Server datatypes.
Some Open Server applications may support CS_LONGBINARY. An application uses the CS_DATA_LBIN capability to determine whether an Open Server connection supports CS_LONGBINARY. If it does, then ct_describe returns CS_LONGBINARY when describing a result data item.
A CS_LONGBINARY value has a maximum length of 2,147,483,647 bytes. CS_LONGBINARY is defined as:
typedef unsigned char CS_LONGBINARY;
CS_VARBINARY does not correspond to any SQL Server type. For this reason, Open Client routines do not return CS_VARBINARY_TYPE. CS_VARBINARY is provided to enable non-C programming language veneers to be written for Open Client. Typical client applications will not use CS_VARBINARY.
CS_VARBINARY is defined as:
typedef struct _cs_varybin
{CS_SMALLINT len;
CS_BYTE array[CS_MAX_CHAR];
} CS_VARBINARY;
where:
len is the length of the binary array.
array is the array itself.
Although CS_VARBINARY variables are used to store variable-length values, CS_VARBINARY is considered to be a fixed-length type. This means that an application does not typically need to provide Client-Library with the length of a CS_VARBINARY variable. For example, ct_bind ignores the value of datafmt−>maxlength when binding to a CS_VARBINARY variable.
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:
CS_CHAR corresponds to the Adaptive Server types char and varchar. That is, Client-Library interprets both the server char and varchar types as CS_CHAR. For example, ct_describe returns CS_CHAR_TYPE when describing a result column that has the server datatype varchar.
CS_CHAR is defined as:
typedef char CS_CHAR;
Warning!
CS_LONGCHAR and CS_VARCHAR do not correspond to any SQL Server datatypes. Specifically, CS_VARCHAR does not correspond to the SQL Server datatype varchar.
CS_LONGCHAR does not correspond to any SQL Server type, but some Open Server applications may support CS_LONGCHAR. An application uses the CS_DATA_LCHAR capability to determine whether an Open Server connection supports CS_LONGCHAR. If it does, then ct_describe returns CS_LONGCHAR when describing a result data item.
A CS_LONGCHAR value has a maximum length of 2,147,483,647 bytes. CS_LONGCHAR is defined as:
typedef unsigned char CS_LONGCHAR;
CS_VARCHAR does not correspond to any SQL Server type. For this reason, Open Client routines do not return CS_VARCHAR_TYPE. CS_VARCHAR is provided to enable non-C programming language veneers to be written for Open Client. Typical client applications will not use CS_VARCHAR.
CS_VARCHAR is defined as:
typedef struct _cs_varchar
{CS_SMALLINT len;
CS_CHAR str[CS_MAX_CHAR];
} CS_VARCHAR;
where:
len is the length of the string.
str is the string itself. Note that str is not null-terminated.
Although CS_VARCHAR variables are used to store variable-length values, CS_VARCHAR is considered to be a fixed-length type. This means that an application does not typically need to provide Client-Library with the length of a CS_VARCHAR variable. For example, ct_bind ignores the value of datafmt−>maxlength when binding to a CS_VARCHAR variable.
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.
CS_DATETIME corresponds to the Adaptive Server datetime datatype. The range of legal CS_DATETIME values is from January 1, 1753 to December 31, 9999, with a precision of 1/300th of a second (3.33 ms.). The definition of CS_DATETIME is:
typedef struct _cs_datetime
{CS_INT dtdays;
CS_INT dttime;
} CS_DATETIME;
where:
dtdays is the number of days since 1/1/1900.
dttime is the number of 300ths of a second since midnight.
CS_DATETIME4 corresponds to the Adaptive Server smalldatetime datatype. The range of legal CS_DATETIME4 values is from January 1, 1900 to June 6, 2079, with a precision of 1 minute. The definition of CS_DATETIME is:
typedef struct _cs_datetime4
{CS_USHORT days;
CS_USHORT minutes;
} CS_DATETIME4;
where:
days is the number of days since 1/1/1900.
minutes is the number of minutes since midnight.
Open Client supports a wide range of numeric types.
Integer types include CS_TINYINT, a 1-byte integer; CS_SMALLINT, a 2-byte integer, and CS_INT, a 4-byte integer:
typedef unsigned char CS_TINYINT;
typedef short CS_SMALLINT;
typedef long CS_INT;
CS_REAL corresponds to the Adaptive Server datatype real. It is implemented as a C-language float type:
typedef float CS_REAL;
CS_FLOAT corresponds to the Adaptive Server datatype float. It is implemented as a C-language double type:
typedef double CS_FLOAT;
CS_NUMERIC and CS_DECIMAL correspond to the Adaptive Server datatypes numeric and decimal. These types provide platform-independent support for numbers with precision and scale.
The Adaptive Server datatypes numeric and decimal are equivalent; and CS_DECIMAL is defined as CS_NUMERIC:
typedef struct_cs_numeric
{CS_BYTE precision;
CS_BYTE scale;
CS_BYTE array[CS_MAX_NUMLEN];
} CS_NUMERIC;
typedef CS_NUMERIC CS_DECIMAL;
where:
precision is the maximum number of decimal digits that are represented. At the current time, legal values for precision are from 1 to 77. The default precision is 18. CS_MIN_PREC, CS_MAX_PREC, and CS_DEF_PREC define the minimum, maximum, and default precision values, respectively.
scale is the maximum number of digits to the right of the decimal point. At the current time, legal values for scale are from 0 to 77. The default scale is 0. CS_MIN_SCALE, CS_MAX_SCALE, and CS_DEF_PREC define the minimum, maximum, and default scale values, respectively.
scale must be less than or equal to precision.
CS_DECIMAL types use the same default values for precision and scale as CS_NUMERIC 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.
CS_MONEY corresponds to the Adaptive Server money datatype. The range of legal CS_MONEY values is between +$922,337,203,685,477.5807 and -$922,337,203,685,477.5807:
typedef struct _cs_money
{CS_INT mnyhigh;
CS_UINT mnylow;
} CS_MONEY;
CS_MONEY4 corresponds to the Adaptive Server smallmoney datatype. The range of legal CS_MONEY4 values is between -$214,748.3648 and +$214,748.3647:
typedef struct _cs_money4
{CS_INT mny4;
} CS_MONEY4;
Open Client supports a text datatype, CS_TEXT, and an image datatype, CS_IMAGE.
CS_TEXT corresponds to the Adaptive Server datatype text, which describes a variable-length column containing up to 2,147,483,647 bytes of printable character data. CS_TEXT is defined as unsigned character:
typedef unsigned char CS_TEXT;
CS_IMAGE corresponds to the Adaptive Server datatype image, which describes a variable-length column containing up to 2,147,483,647 bytes of binary data. CS_IMAGE is defined as unsigned character:
typedef unsigned char CS_IMAGE;
|
|