Getting descriptions of result data

Applications need to determine the number of items in a result set and the format of each item before they can bind items and fetch rows.

Applications that process the results of known queries have this information already, but applications that process the results of ad hoc queries do not.

To handle the results of an ad hoc query, the application must:


Obtaining the number of items in a result set

In DB-Library, an application calls different routines to obtain the number of items in a result set, depending on the type of results being retrieved.

In Client-Library, whenever the ct_results result_type parameter indicates fetchable data, the application can retrieve the number of data items by calling ct_res_info(CS_NUMDATA).

Table 5-12 lists DB-Library routines that ct_res_info(CS_NUMDATA) replaces:

Table 5-12: DB-Library routines that convert to ct_res_info(CS_NUMDATA)

Routine

Description

dbnumalts

Returns the number of columns in a compute row

dbnumcols

Determines the number of regular columns for the current set of results

dbnumrets

Determines the number of return parameter values generated by a stored procedure


Obtaining Format Descriptions for Individual Items

A DB-Library application calls several routines to get a description of a data item.

A Client-Library application calls ct_describe once to initialize a CS_DATAFMT structure that completely describes any data value.

Table 5-13 lists DB-Library routines that ct_describe replaces:

Table 5-13: DB-Library data description routines vs. CS_DATAFMT fields

DB-Library routine

Value returned

CS_DATAFMT field (set by ct_describe)

dbaltlen

The maximum length of data for a particular compute column

maxlength

dbcollen

The maximum length of data for a particular regular result column

maxlength

dbretlen

The length of a stored procedure return parameter value

maxlength

dbalttype

The datatype of a compute column

datatype

dbcoltype

The datatype of a regular result column

datatype

dbrettype

The datatype of a stored procedure return parameter value

datatype

dbaltutype

The user-defined datatype for a compute column

usertype

dbcolutype

The user-defined datatype for a regular result column

usertype

dbcolname

The name of a regular result column

name

dbretname

The name of a stored procedure parameter for a particular return parameter value

name

dbdatlen

The actual length of a regular result column value

None. This information is returned using ct_bind’s copied parameter or ct_get_data’s outlen parameter.

dbadlen

The actual length of a compute column value

dbretlen

The actual length of a return parameter value