DB2 10.5 for Linux, UNIX, and Windows

SQLNumResultCols function (CLI - Get number of result columns

Returns the number of columns in the result set associated with the input statement handle.

Specification:

SQLPrepare() or SQLExecDirect() must be called before calling this function.

After calling this function, you can call SQLColAttribute(), or one of the bind column functions.

Syntax

SQLRETURN   SQLNumResultCols (
               SQLHSTMT          StatementHandle,   /* hstmt */
               SQLSMALLINT       *ColumnCountPtr);  /* pccol */

Function arguments

Table 1. SQLNumResultCols arguments
Data type Argument Use Description
SQLHSTMT StatementHandle input Statement handle
SQLSMALLINT * ColumnCountPtr output Number of columns in the result set

Usage

The function sets the output argument to zero if the last statement or function executed on the input statement handle did not generate a result set.

Return codes

Diagnostics

Table 2. SQLNumResultCols SQLSTATEs
SQLSTATE Description Explanation
40003 08S01 Communication link failure. The communication link between the application and data source failed before the function completed.
58004 Unexpected system failure. Unrecoverable system error.
HY001 Memory allocation failure. DB2® CLI is unable to allocate memory required to support execution or completion of the function. It is likely that process-level memory has been exhausted for the application process. Consult the operating system configuration for information about process-level memory limitations.
HY008 Operation was Canceled. Asynchronous processing was enabled for StatementHandle. The function was called and before it completed execution, SQLCancel() was called on StatementHandle from a different thread in a multithreaded application. Then the function was called again on StatementHandle.
HY010 Function sequence error. The function was called before calling SQLPrepare() or SQLExecDirect() for the StatementHandle.

The function was called while in a data-at-execute (SQLParamData(), SQLPutData()) operation.

The function was called while within a BEGIN COMPOUND and END COMPOUND SQL operation.

HY013 Unexpected memory handling error. DB2 CLI was unable to access memory required to support execution or completion of the function.
HYT00 Timeout expired. The timeout period expired before the data source returned the result set. The timeout period can be set using the SQL_ATTR_QUERY_TIMEOUT attribute for SQLSetStmtAttr().

Authorization

None.

Example

  /* identify the number of output columns */
  cliRC = SQLNumResultCols(hstmt, &nResultCols);