diff --git a/cpp/src/arrow/flight/sql/odbc/tests/statement_test.cc b/cpp/src/arrow/flight/sql/odbc/tests/statement_test.cc index 89fce1a23d22..0d255101db39 100644 --- a/cpp/src/arrow/flight/sql/odbc/tests/statement_test.cc +++ b/cpp/src/arrow/flight/sql/odbc/tests/statement_test.cc @@ -2470,6 +2470,76 @@ TYPED_TEST(FlightSQLODBCTestBase, SQLNumResultColsFunctionSequenceErrorOnNoQuery this->disconnect(); } +TYPED_TEST(FlightSQLODBCTestBase, SQLRowCountReturnsNegativeOneOnSelect) { + this->connect(); + + SQLLEN rowCount = 0; + SQLLEN expectedValue = -1; + SQLWCHAR sqlQuery[] = L"SELECT 1 AS col1, 'One' AS col2, 3 AS col3"; + SQLINTEGER queryLength = static_cast(wcslen(sqlQuery)); + + SQLRETURN ret = SQLExecDirect(this->stmt, sqlQuery, queryLength); + + EXPECT_EQ(ret, SQL_SUCCESS); + + ret = SQLFetch(this->stmt); + + EXPECT_EQ(ret, SQL_SUCCESS); + + CheckIntColumn(this->stmt, 1, 1); + CheckStringColumnW(this->stmt, 2, L"One"); + CheckIntColumn(this->stmt, 3, 3); + + ret = SQLRowCount(this->stmt, &rowCount); + + EXPECT_EQ(ret, SQL_SUCCESS); + + EXPECT_EQ(rowCount, expectedValue); + + this->disconnect(); +} + +TYPED_TEST(FlightSQLODBCTestBase, SQLRowCountReturnsSuccessOnNullptr) { + this->connect(); + + SQLWCHAR sqlQuery[] = L"SELECT 1 AS col1, 'One' AS col2, 3 AS col3"; + SQLINTEGER queryLength = static_cast(wcslen(sqlQuery)); + + SQLRETURN ret = SQLExecDirect(this->stmt, sqlQuery, queryLength); + + EXPECT_EQ(ret, SQL_SUCCESS); + + ret = SQLFetch(this->stmt); + + EXPECT_EQ(ret, SQL_SUCCESS); + + CheckIntColumn(this->stmt, 1, 1); + CheckStringColumnW(this->stmt, 2, L"One"); + CheckIntColumn(this->stmt, 3, 3); + + ret = SQLRowCount(this->stmt, 0); + + EXPECT_EQ(ret, SQL_SUCCESS); + + this->disconnect(); +} + +TYPED_TEST(FlightSQLODBCTestBase, SQLRowCountFunctionSequenceErrorOnNoQuery) { + this->connect(); + + SQLLEN rowCount = 0; + SQLLEN expectedValue = 0; + + SQLRETURN ret = SQLRowCount(this->stmt, &rowCount); + + EXPECT_EQ(ret, SQL_ERROR); + VerifyOdbcErrorState(SQL_HANDLE_STMT, this->stmt, error_state_HY010); + + EXPECT_EQ(rowCount, expectedValue); + + this->disconnect(); +} + TYPED_TEST(FlightSQLODBCTestBase, TestSQLFreeStmtSQLClose) { this->connect();