ct_bind versus dbbind

DB-Library provides four similar bind routines:

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:

Table 5-10: dbbind_ps parameters vs. 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.

datafmtdatatype

datatype is a symbol (CS_xxx_TYPE) representing the datatype of the destination variable.

datafmtformat

format is a symbol describing the destination format of character or binary data.

varlen

The length of the program variable in bytes.

datafmtmaxlength

The length of the buffer destination variable in bytes.

typeinfoprecision

typeinfoscale

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.

datafmtprecision

datafmtscale

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)

datafmtcount

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 datafmtcount variables, each of which is of size datafmtmaxlength.

(none)

copied

The address of an array of datafmtcount 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 datafmtcount 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:

Table 5-11: DB-Library vartype vs. CS_DATAFMT datatype and format fields

Program variable type

DB-Library vartype

CS_DATAFMTdatatype

CS_DATAFMTformat

DBCHAR

CHARBIND

CS_CHAR_TYPE

CS_FMT_PADBLANK

DBCHAR

STRINGBIND

CS_CHAR_TYPE

CS_FMT_NULLTERM

DBCHAR

NTBSTRINGBIND

CS_CHAR_TYPE

CS_FMT_NULLTERM

NoteClient-Library does not trim trailing blanks.

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 column data, only values that originate as a fixed-length char column will have trailing blanks to begin with, because Adaptive Server 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.