dbcursorbind

Description

Register the binding information on the cursor columns.

Syntax

RETCODE dbcursorbind(hc, col, vartype, varlen,
                   poutlen, pvaraddr, typeinfo)
 
DBCURSOR   *hc;
int                     col;
int                     vartype;
DBINT              varlen;
DBINT             *poutlen;
BYTE              *pvaraddr;
DBTYPEINFO  *typeinfo;

Parameters

hc

Cursor handle created by dbcursoropen.

col

Number of the column to be bound to a program variable.

vartype

Binding type, which uses the same datatypes as the vartype parameter for dbbind and is bound by the same conversion rules. If this value is set to NOBIND for any column, the data is not bound. Instead, a pointer to the data is returned to the address in the corresponding pvaraddr entry for every row, and the length of the data is returned to the corresponding varlen array entry. This feature lets the application access the cursor data as it does with dbdata and dbdatalen.

varlen

Maximum length of variable-length datatype, such as CHARBIND, VARYCHARBIND, BINARYBIND, STRINGBIND, NTBSTRINGBIND, and VARYBINBIND. This parameter is ignored for fixed-length datatypes, such as INTBIND, FLT8BIND, MONEYBIND, BITBIND, SMALLBIND, and so on. It is also ignored if the vartype is NOBIND.

poutlen

Pointer to an array of DBINT integers where the actual length of the column’s data is returned for each row. If poutlen is set to NULL, the lengths are not returned. The array size must be large enough to hold one DBINT variable for every row to be fetched at a time (as indicated by the nrows parameter in dbcursoropen).

When using dbcursor to update or insert with values from bound program variables, you can specify a null value by setting the corresponding poutlen to zero before calling dbcursor. Nonzero values are ignored except when NOBIND or one of the variable-length datatypes such as VARYCHARBIND or VARYBINBIND has been specified. In that case poutlen must contain the actual item length. If STRINGBIND or NTBSTRINGBIND has been specified, any non-zero value for poutlen is ignored, and the length of the string is determined by scanning for the null terminator.

pvaraddr

Pointer to the program variable to which the data is copied. If vartype is NOBIND, pvaraddr is assumed to point to an array of pointers—to the address of the actual data fetched by dbcursorfetch. This array’s length must equal the value of nrows in dbcursoropen. If the cursor was opened with nrows > 1, pvaraddr is assumed to point to an array of nrows elements. Calling dbcursorbind with pvaraddr set to NULL breaks the existing binding.

typeinfo

A pointer to a DBTYPEINFO structure containing information about the precision and scale of decimal or numeric values. If vartype is not DECIMALBIND or NUMERICBIND, typeinfo is ignored.

To bind to DBNUMERIC or DBDECIMAL variables, an application initializes a DBTYPEINFO structure with values for precision and scale, then calls dbcursorbind with vartype as DECIMALBIND or NUMERICBIND.

If typeinfo is NULL and vartype is DECIMALBIND or NUMERICBIND:

  • If the result column is of type numeric or decimal, dbcursorbind picks up precision and scale values from the result column.

  • If the result column is not numeric or decimal, dbcursorbind uses a default precision of 18 and a default scale of 0.

A DBTYPEINFO structure is defined as follows:

typedef struct typeinfo {
      DBINTprecision;
      DBINTscale;
 } DBTYPEINFO;

Legal values for precision are from 1 to 77. Legal values for scale are from 0 to 77. scale must be less than or equal to precision.

Returns

SUCCEED or FAIL.

Usage

See also

dbcursor, dbcursorclose, dbcursorcolinfo, dbcursorfetch, dbcursorinfo, dbcursoropen