DB-Library provides four similar bind routines:
dbbind – binds regular row columns
dbbind_ps (version 10.0 and later) – same as dbbind but provides precision and scale support for decimal and numeric datatypes
dbaltbind – binds compute row columns
dbaltbind_ps (version 10.0 and later) – same as dbaltbind_ps but provides precision and scale support for decimal and numeric datatypes
If you understand how dbbind_ps usage maps to ct_bind usage, you will be able to convert any other DB-Library bind routine call to an equivalent ct_bind call. dbbind_ps is an enhancement of dbbind. It takes as an additional parameter a DBTYPEINFO structure to convey precision and scale information about numeric and decimal datatypes. For datatypes other than numeric and decimal, the additional parameter is ignored, and dbbind_ps is equivalent to dbbind.
Table 5-10 compares dbbind_ps parameters to ct_bind parameters:
dbbind_ps parameter |
Parameter description |
ct_bind parameter |
Parameter description |
---|---|---|---|
dbproc |
A pointer to the DBPROCESS structure for this connection. |
cmd |
A pointer to the CS_COMMAND structure. |
column |
An integer representing the number of the column to bind. |
item |
An integer representing the number of the column to bind. |
datafmt |
A pointer to the CS_DATAFMT structure that describes the destination variable. |
||
vartype |
A symbolic value corresponding to the datatype of the program variable that will receive the copy of the data from the DBPROCESS. |
datafmt→datatype |
datatype is a symbol (CS_xxx_TYPE) representing the datatype of the destination variable. |
datafmt→format |
format is a symbol describing the destination format of character or binary data. |
||
varlen |
The length of the program variable in bytes. |
datafmt→maxlength |
The length of the buffer destination variable in bytes. |
typeinfo→precision typeinfo→scale |
typeinfo is a pointer to a DBTYPEINFO structure, which contains information about the precision and scale of decimal or numeric data. typeinfo of NULL is equivalent to calling dbbind. |
datafmt→precision datafmt→scale |
The precision and scale to be used for the destination variable. If the source data is the same type as the destination, then scale and precision can be set to CS_SRC_VALUE to pick up the value from the source data. |
(none) |
datafmt→count |
The number of rows to copy to program variables per ct_fetch call. (Set to 1 if not binding to arrays.) |
|
varaddr |
The address of the program variable to which the data is to be copied. |
buffer |
The address of an array of datafmt→count variables, each of which is of size datafmt→maxlength. |
(none) |
copied |
The address of an array of datafmt→count integer variables, to be filled at fetch time with the lengths of the copied data (optional). |
|
(none—the routines dbnullbind and dbanullbind bind indicator variables) |
indicator |
The address of an array of datafmt→count CS_SMALLINT variables, to be filled at fetch time to indicate certain conditions about the fetched data. |
The mapping of DB-Library vartype values to Client-Library CS_DATAFMT datatype and format values is straightforward for all of the fixed-length datatypes.
For character and binary types, the mapping is shown in Table 5-11:
Program variable type |
DB-Library vartype |
CS_DATAFMT→datatype |
CS_DATAFMT→format |
---|---|---|---|
DBCHAR |
CHARBIND |
CS_CHAR_TYPE |
CS_FMT_PADBLANK |
DBCHAR |
STRINGBIND |
CS_CHAR_TYPE |
CS_FMT_NULLTERM |
DBCHAR |
NTBSTRINGBIND |
CS_CHAR_TYPE |
CS_FMT_NULLTERM
|
DBVARYCHAR |
VARYCHARBIND |
CS_VARCHAR_TYPE |
CS_FMT_UNUSED |
DBBINARY |
BINARYBIND |
CS_BINARY_TYPE |
CS_FMT_PADNULL |
DBVARYBIN |
VARYBINBIND |
CS_VARBINARY_TYPE |
CS_FMT_UNUSED |
With dbbind, passing NTBSTRINGBIND for vartype causes DB-Library to trim trailing blanks from the destination string. Client-Library lacks a format option to strip trailing blanks.
For Adaptive Server Enterprise column data, only values that originate as a fixed-length char column will have trailing blanks to begin with, because Adaptive Server Enterprise trims trailing blanks from varchar columns on entry.
If a DB-Library application relies on NTBSTRINGBIND behavior, the Client-Library version of the application must trim any trailing blanks itself.