Determine whether the current command or remote procedure call generated a return status number.
DBBOOL dbhasretstat(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.
“TRUE” or “FALSE”.
This routine determines whether the current Transact-SQL command or remote procedure call generated a return status number. Status numbers are returned by all stored procedures running on Adaptive Server Enterprise. Since status numbers are a feature of stored procedures, only a remote procedure call or an execute command can generate a status number.
The dbretstatus routine actually gets the 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.
When executing a stored procedure, the server returns the status number immediately after returning all other results. Therefore, the application can call dbhasretstat 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 dbhasretstat or dbretstatus, 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 as an RPC command using dbrpcinit, dbrpcparam, and dbrpcsend, then the return status can be retrieved after all other results have been processed. For an example of this usage, see the sample program example8.c.
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. The code below shows the program logic to retrieve the return status value in this situation.
while ( (result_code = dbresults(dbproc)
!= NO_MORE_RESULTS)
{
if (result_code == SUCCEED)
{
... bind rows here ...
while ((row_code = dbnextrow(dbproc))
!= NO_MORE_ROWS)
{
... process rows here ...
}
/* Now check for a return status */
if (dbhasretstat(dbproc) == TRUE)
{
printf(“(return status %d)\n”,
dbretstatus(dbproc));
}
if (dbnumrets(dbproc) > 0)
{
... get output parameters here ...
}
} /* if result_code */
else
{
printf(“Query failed.\n”);
}
} /* while dbresults */
dbnextrow, dbresults, dbretdata, dbretstatus, dbrpcinit, dbrpcparam, dbrpcsend