Skip to content

Commit e841e88

Browse files
committed
Extract SQLMoreResults implementation
Nit updates Co-Authored-By: alinalibq <[email protected]>
1 parent b2e8f25 commit e841e88

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

cpp/src/arrow/flight/sql/odbc/odbc_api.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,8 +1111,14 @@ SQLRETURN SQLGetData(SQLHSTMT stmt, SQLUSMALLINT record_number, SQLSMALLINT c_ty
11111111

11121112
SQLRETURN SQLMoreResults(SQLHSTMT stmt) {
11131113
ARROW_LOG(DEBUG) << "SQLMoreResults called with stmt: " << stmt;
1114-
// GH-47713 TODO: Implement SQLMoreResults
1115-
return SQL_INVALID_HANDLE;
1114+
1115+
using ODBC::ODBCStatement;
1116+
// Multiple result sets are not supported by Arrow protocol. Return SQL_NO_DATA by
1117+
// default to indicate no data is available.
1118+
return ODBCStatement::ExecuteWithDiagnostics(stmt, SQL_ERROR, [=]() {
1119+
ODBCStatement* statement = reinterpret_cast<ODBCStatement*>(stmt);
1120+
return statement->GetMoreResults();
1121+
});
11161122
}
11171123

11181124
SQLRETURN SQLNumResultCols(SQLHSTMT stmt, SQLSMALLINT* column_count_ptr) {

cpp/src/arrow/flight/sql/odbc/odbc_impl/odbc_statement.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,15 @@ bool ODBCStatement::GetData(SQLSMALLINT record_number, SQLSMALLINT c_type,
751751
data_ptr, buffer_length, indicator_ptr);
752752
}
753753

754+
SQLRETURN ODBCStatement::GetMoreResults() {
755+
// Multiple result sets are not supported by Arrow protocol.
756+
if (current_result_) {
757+
return SQL_NO_DATA;
758+
} else {
759+
throw DriverException("Function sequence error", "HY010");
760+
}
761+
}
762+
754763
void ODBCStatement::ReleaseStatement() {
755764
CloseCursor(true);
756765
connection_.DropStatement(this);

cpp/src/arrow/flight/sql/odbc/odbc_impl/odbc_statement.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class ODBCStatement : public ODBCHandle<ODBCStatement> {
8080
bool GetData(SQLSMALLINT record_number, SQLSMALLINT c_type, SQLPOINTER data_ptr,
8181
SQLLEN buffer_length, SQLLEN* indicator_ptr);
8282

83+
SQLRETURN GetMoreResults();
84+
8385
/**
8486
* @brief Closes the cursor. This does _not_ un-prepare the statement or change
8587
* bindings.

cpp/src/arrow/flight/sql/odbc/tests/statement_test.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,24 @@ TYPED_TEST(StatementTest, TestSQLPrepareInvalidQuery) {
114114
VerifyOdbcErrorState(SQL_HANDLE_STMT, this->stmt, kErrorStateHY010);
115115
}
116116

117+
TYPED_TEST(StatementTest, TestSQLMoreResultsNoData) {
118+
// Verify SQLMoreResults returns SQL_NO_DATA by default.
119+
std::wstring wsql = L"SELECT 1;";
120+
std::vector<SQLWCHAR> sql0(wsql.begin(), wsql.end());
121+
122+
ASSERT_EQ(SQL_SUCCESS,
123+
SQLExecDirect(this->stmt, &sql0[0], static_cast<SQLINTEGER>(sql0.size())));
124+
125+
ASSERT_EQ(SQL_NO_DATA, SQLMoreResults(this->stmt));
126+
}
127+
128+
TYPED_TEST(StatementTest, TestSQLMoreResultsInvalidFunctionSequence) {
129+
// Verify function sequence error state is reported when SQLMoreResults is called
130+
// without executing any queries
131+
ASSERT_EQ(SQL_ERROR, SQLMoreResults(this->stmt));
132+
VerifyOdbcErrorState(SQL_HANDLE_STMT, this->stmt, kErrorStateHY010);
133+
}
134+
117135
TYPED_TEST(StatementTest, TestSQLNativeSqlReturnsInputString) {
118136
SQLWCHAR buf[1024];
119137
SQLINTEGER buf_char_len = sizeof(buf) / GetSqlWCharSize();

0 commit comments

Comments
 (0)