Skip to content

SQLNumResultCols

SQLNumResultCols#

SQLNumResultCols returns the number of columns in a result set.

Syntax#

SQLRETURN  SQLNumResultCols (
    SQLHSTMT            stmt,
    SQLSMALLINT *       col );

Arguments#

Data Type Argument In/Output Description
SQLHSTMT stmt Input Statement handle
SQLSMALLINT * col Output Pointer to save the number of columns in a result set.

Return Values#

SQL_SUCCESS
SQL_SUCCESS_WITH_INFO
SQL_INVALID_HANDLE
SQL_ERROR

Description#

If the commands related to stmt do not return columns, SQLNumResultCols() will set 0 in *col.

This function can be called only after SQLPrepare() or SQLExecDirect() is called. After this function is called, SQLDescribeCol(), SQLColAttribute(), SQLBindCol() or SQLGetData() can be called.

When the command is in ready, executed, or defined status, SQLNumResultCols() can be successfully called.

Diagnosis#

SQLSTATE Description Comments
08S01 Communication channel error Communication channel failure before the function processing is completed between the Altibase CLI driver and the database
HY000 General error

If SQLNumResultCols() is called after SQLPrepare() and before SQLExecute(), no SQLSTATE returned by these two functions can be returned.

SQLBindCol
SQLColAttribute
SQLDescribeCol  
SQLExecDirect
SQLExecute
SQLFetch
SQLGetData
SQLPrepare
SQLSetStmtAttr

Example#

< Refer to: $ALTIBASE_HOME/sample/SQLCLI/demo_ex1.cpp >

sprintf(query,"SELECT * FROM DEMO_EX1");
if (SQLExecDirect(stmt,query, SQL_NTS) != SQL_SUCCESS)
{
    execute_err(dbc, stmt, query);
    SQLFreeStmt(stmt, SQL_DROP);
    return SQL_ERROR;
}           
SQLNumResultCols(stmt, &columnCount);