Programming Db2 ODBC client applications to receive result sets
After you execute a stored procedure from a client application, you receive the result sets from that stored procedure. You receive these result sets in the same way that you receive result sets from a query.
Procedure
To write a Db2 ODBC client application that receives result sets from a stored procedure:
- Ensure that no open cursors are associated with the statement handle on which you plan to issue the CALL SQL statement.
- Call
SQLPrepare()
andSQLExecute()
, or callSQLExecDirect()
to issue the CALL SQL statement for the stored procedure that you want to invoke.This execution of the CALL SQL statement effectively causes the cursors that are associated with the result sets to open. - Examine output parameters that
the stored procedure returns. For example, the procedure might be designed with an output parameter that indicates exactly how many result sets are generated. You could then use this information to receive those result sets more efficiently.
- If you do not know the nature of the result set, or the
number of columns that the result set is to contain, call
SQLNumResultCols()
,SQLDescribeCol()
, orSQLColAttribute()
- You must process result sets serially. You receive each result set one at a time in the order that the stored procedure opens the corresponding cursors.
- Use any permitted combination
of
SQLBindCol()
,SQLFetch()
, andSQLGetData()
to obtain the data set from the current cursor.When you finish processing the current result set, callSQLMoreResults()
to check for more result sets to receive. If an additional result set exists,SQLMoreResults()
returns SQL_SUCCESS, closes the current cursor, and advances processing to the next open cursor. Otherwise,SQLMoreResults()
returns SQL_NO_DATA_FOUND. Repeat steps 3 through 6 until you receive all result sets that the stored procedure returned.