Determine the stored procedure status number returned by the current command or remote procedure call.
DBINT dbretstatus(dbproc) DBPROCESS *dbproc;
A pointer to the DBPROCESS structure that provides the connection for a particular front-end/server process. It contains all the information that DB-Library uses to manage communications and data between the front end and server.
The return status number for the current command.
dbretstatus fetches a stored procedure’s status number. All stored procedures that are run on Adaptive Server Enterprise return a status number. Stored procedures that complete normally return a status number of 0. For a list of return status numbers, see the Adaptive Server Enterprise Reference Manual.
The dbhasretstat routine determines whether the current Transact-SQL command or remote procedure call actually generated a return status number. Since status numbers are a feature of stored procedures, only a remote procedure call or a Transact-SQL command that executes a stored procedure can generate a status number.
When executing a stored procedure, the server returns the status number immediately after returning all other results. Therefore, the application can call dbretstatus only after processing the stored procedure’s results by calling dbresults, as well as dbnextrow if appropriate. (Note that a stored procedure can generate several sets of results—one for each select it contains. Before the application can call dbretstatus or dbhasretstat, it must call dbresults and dbnextrow as many times as necessary to process all the results.)
The order in which the application processes the status number and any return parameter values is unimportant.
When a stored procedure has been executed from a batch of Transact-SQL commands (with dbsqlexec or dbsqlsend), then other commands might execute after the stored procedure. This situation makes return-status retrieval a little more complicated.
If you are sure that the stored procedure command is the only command in the batch, then you can retrieve the return status after the dbresults loop, as shown in the sample program example8.c.
If the batch can contain multiple commands, then the return status should be retrieved inside the dbresults loop, after all rows have been fetched with dbnextrow. For an example of how return statuses are retrieved in this situation, see the dbhasretstat reference page.
For an example of this routine, see the dbhasretstat reference page.
dbhasretstat, dbnextrow, dbresults, dbretdata, dbrpcinit, dbrpcparam, dbrpcsend