Skip to content

SQLRowCount

SQLRowCount#

SQLRowCount returns the number of rows affected by an UPDATE, DELETE,or INSERT statement. This function can return a maximum of 2,147,483,647 rows (the range of a 32-bit integer). If the number of affected rows is likely to exceed this range, use the SQLRowCount2 function.

Syntax#

SQLRETURN  SQLRowCount (
    SQLHSTMT        stmt,
    SQLLEN *        row );

Arguments#

Data Type Argument In/Output Description
SQLHSTMT stmt Input Statement handle
SQLLEN * row Output Pointer to save the number of row

Return Values#

SQL_SUCCESS
SQL_SUCCESS_WITH_INFO
SQL_INVALID_HANDLE
SQL_ERROR

Description#

This function returns the number of rows affected by an UPDATE, INSERT or DELETE statement. For SQL statements which alter rows, such as MOVE, ENQUEUE and MERGE, the number of affected rows is returned in *row; if no rows are affected, 0 is returned.

If the SQL statement which was most recently executed by the input statement handle is not one listed above, or it failed to execute successfully, this function returns -1 in *row.

The rows in the tables affected by the SQL statement such as cascading delete operationare not included.

Before this funciton is called, SQLExecute() or SQLExecDirect() must be called.

Diagnosis#

SQLSTATE Description Comments
HY000 General error
SQLExecDirect
SQLExecute

Example#

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

if (SQLExecute(stmt) != SQL_SUCCESS)
{
    execute_err(dbc, stmt, query);
    SQLFreeStmt(stmt, SQL_DROP);
    return SQL_ERROR;
}
SQLRowCount(stmt, &row_count);

SQLRowCount2#

SQLRowCount2 also returns the number of rows affected by an UPDATE, DELETE,or INSERT statement. Unlike the SQLRowCount function, it can return the number of affected rows up to the maximum range of a 64-bit integer.

Syntax#

SQLRETURN  SQLRowCount2 (
    SQLHSTMT        stmt,
    SQLBIGINT *     row );

Arguments#

Data Type Argument In/Output Description
SQLHSTMT stmt Input Statement handle
SQLBIGINT * row Output Pointer to save the number of row

Return Values#

SQL_SUCCESS
SQL_SUCCESS_WITH_INFO
SQL_INVALID_HANDLE
SQL_ERROR

Description#

This function returns the number of rows affected by an UPDATE, INSERT or DELETE statement. For SQL statements which alter rows, such as MOVE, ENQUEUE and MERGE, the number of affected rows is returned in *row; if no rows are affected, 0 is returned.

If the SQL statement which was most recently executed by the input statement handle is not one listed above, or it failed to execute successfully, this function returns -1 in *row.

The rows in the tables affected by the SQL statement such as cascading delete operationare not included.

Before this funciton is called, SQLExecute() or SQLExecDirect() must be called.

Diagnosis#

SQLSTATE Description Comments
HY000 General error
SQLExecDirect
SQLExecute

Example#

Refer to the example of the SQLRowCount function.