lidavidm commented on code in PR #48041:
URL: https://github.com/apache/arrow/pull/48041#discussion_r2600211084
##########
cpp/src/arrow/flight/sql/odbc/tests/statement_test.cc:
##########
@@ -715,6 +715,100 @@ TYPED_TEST(StatementTest, TestSQLExecDirectRowFetching) {
VerifyOdbcErrorState(SQL_HANDLE_STMT, this->stmt, kErrorState24000);
}
+TYPED_TEST(StatementTest, TestSQLFetchScrollRowFetching) {
+ SQLLEN rows_fetched;
+ SQLSetStmtAttr(this->stmt, SQL_ATTR_ROWS_FETCHED_PTR, &rows_fetched, 0);
+
+ std::wstring wsql =
+ LR"(
+ SELECT 1 AS small_table
+ UNION ALL
+ SELECT 2
+ UNION ALL
+ SELECT 3;
+ )";
+ std::vector<SQLWCHAR> sql0(wsql.begin(), wsql.end());
+
+ ASSERT_EQ(SQL_SUCCESS,
+ SQLExecDirect(this->stmt, &sql0[0],
static_cast<SQLINTEGER>(sql0.size())));
+
+ // Fetch row 1
+ ASSERT_EQ(SQL_SUCCESS, SQLFetchScroll(this->stmt, SQL_FETCH_NEXT, 0));
+
+ SQLINTEGER val;
+ SQLLEN buf_len = sizeof(val);
+ SQLLEN ind;
+
+ ASSERT_EQ(SQL_SUCCESS, SQLGetData(this->stmt, 1, SQL_C_LONG, &val, buf_len,
&ind));
+ // Verify 1 is returned
+ EXPECT_EQ(1, val);
+ // Verify 1 row is fetched
+ EXPECT_EQ(1, rows_fetched);
+
+ // Fetch row 2
+ ASSERT_EQ(SQL_SUCCESS, SQLFetchScroll(this->stmt, SQL_FETCH_NEXT, 0));
+
+ ASSERT_EQ(SQL_SUCCESS, SQLGetData(this->stmt, 1, SQL_C_LONG, &val, buf_len,
&ind));
+
+ // Verify 2 is returned
+ EXPECT_EQ(2, val);
+ // Verify 1 row is fetched in the last SQLFetchScroll call
+ EXPECT_EQ(1, rows_fetched);
+
+ // Fetch row 3
+ ASSERT_EQ(SQL_SUCCESS, SQLFetchScroll(this->stmt, SQL_FETCH_NEXT, 0));
+
+ ASSERT_EQ(SQL_SUCCESS, SQLGetData(this->stmt, 1, SQL_C_LONG, &val, buf_len,
&ind));
+
+ // Verify 3 is returned
+ EXPECT_EQ(3, val);
+ // Verify 1 row is fetched in the last SQLFetchScroll call
+ EXPECT_EQ(1, rows_fetched);
+
+ // Verify result set has no more data beyond row 3
+ ASSERT_EQ(SQL_NO_DATA, SQLFetchScroll(this->stmt, SQL_FETCH_NEXT, 0));
+
+ ASSERT_EQ(SQL_ERROR, SQLGetData(this->stmt, 1, SQL_C_LONG, &val, 0, &ind));
+ // Invalid cursor state
+ VerifyOdbcErrorState(SQL_HANDLE_STMT, this->stmt, kErrorState24000);
+}
+
+TYPED_TEST(StatementTest, TestSQLFetchScrollUnsupportedOrientation) {
+ // SQL_FETCH_PRIOR is the only supported fetch orientation.
Review Comment:
I think this comment is wrong/not relevant here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]