Results processing

Once a command batch has been executed in the server, indicated by dbsqlexec or dbsqlok returning SUCCEED, the application must process any results. Results can include:

Result rows are returned by select commands and execute commands on stored procedures that contain select commands.

There are two types of result rows: regular rows and compute rows. Regular rows are generated from columns in a select command’s select list; compute rows are generated from columns in a select command’s compute clause. Since these two types of rows contain very different data, the application must process them separately.

The results for each Transact-SQL command in a batch are returned to the application separately. Within each command’s set of results, the result rows are processed one at a time.

If a command batch contains only a single Transact-SQL command and that command returns rows (for example, a select command), an application must call dbresults to process the results of the command.

If a command batch contains only a single Transact-SQL command and that command does not return rows (for example, a use database command or an insert command), an application does not have to call dbresults to process the results of the command. However, calling dbresults in these situations causes no harm. It may result in easier code maintenance if, after every command, you consistently call dbresults until it returns NO_MORE_RESULTS.

If the command batch contains more than one Transact-SQL command, an application must call dbresults once for every command in the batch, whether or not the command returns rows. For this reason, it is recommended that a DB-Library/C application always call dbresults in a loop after sending a command or commands to a server.

Table 1-1 lists Transact-SQL commands and the DB-Library/C functions required to process the results that they return:

Table 1-1: DB-Library/C functions required to process Transact-SQL commands

Transact-SQL command

Required DB-Library/C functions

All Transact-SQL commands not listed elsewhere in this table.

dbresults. In some cases, for example dbcc, the command’s normal output is considered by DB-Library/C to consist of errors and messages. The output is thus processed within a DB-Library/C application’s error and message handlers instead of in the main program using dbnextrow or other DB-Library/C routines.

execute

A DB-Library/C application must call dbresults once for every set of results that the stored procedure returns. In addition, if the stored procedure returns rows, the application must call dbnextrow or other DB-Library/C result-row routines.

select

dbresults. In addition, a DB-Library/C application must call dbnextrow or other DB-Library/C result-row routines.