Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cpp/src/arrow/flight/sql/odbc/odbc_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,16 @@ SQLRETURN SQLBindCol(SQLHSTMT stmt, SQLUSMALLINT record_number, SQLSMALLINT c_ty

SQLRETURN SQLCloseCursor(SQLHSTMT stmt) {
ARROW_LOG(DEBUG) << "SQLCloseCursor called with stmt: " << stmt;
// GH-47717 TODO: Implement SQLCloseCursor
return SQL_INVALID_HANDLE;

using ODBC::ODBCStatement;
return ODBCStatement::ExecuteWithDiagnostics(stmt, SQL_ERROR, [=]() {
ODBCStatement* statement = reinterpret_cast<ODBCStatement*>(stmt);

// Close cursor with suppressErrors set to false
statement->CloseCursor(false);

return SQL_SUCCESS;
});
}

SQLRETURN SQLGetData(SQLHSTMT stmt, SQLUSMALLINT record_number, SQLSMALLINT c_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ void ODBCStatement::RevertAppDescriptor(bool isApd) {

void ODBCStatement::CloseCursor(bool suppress_errors) {
if (!suppress_errors && !current_result_) {
throw DriverException("Invalid cursor state", "28000");
throw DriverException("Invalid cursor state", "24000");
}

if (current_result_) {
Expand Down
10 changes: 3 additions & 7 deletions cpp/src/arrow/flight/sql/odbc/odbc_impl/odbc_statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,11 @@ class ODBCStatement : public ODBCHandle<ODBCStatement> {
bool GetData(SQLSMALLINT record_number, SQLSMALLINT c_type, SQLPOINTER data_ptr,
SQLLEN buffer_length, SQLLEN* indicator_ptr);

/**
* @brief Closes the cursor. This does _not_ un-prepare the statement or change
* bindings.
*/
/// \brief Closes the cursor. This does _not_ un-prepare the statement or change
/// bindings.
void CloseCursor(bool suppress_errors);

/**
* @brief Releases this statement from memory.
*/
/// \brief Releases this statement from memory.
void ReleaseStatement();

void GetTables(const std::string* catalog, const std::string* schema,
Expand Down
1 change: 1 addition & 0 deletions cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ add_arrow_test(flight_sql_odbc_test
odbc_test_suite.cc
odbc_test_suite.h
connection_test.cc
statement_test.cc
# Enable Protobuf cleanup after test execution
# GH-46889: move protobuf_test_util to a more common location
../../../../engine/substrait/protobuf_test_util.cc
Expand Down
63 changes: 63 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/tests/statement_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include "arrow/flight/sql/odbc/tests/odbc_test_suite.h"

#include "arrow/flight/sql/odbc/odbc_impl/platform.h"

#include <sql.h>
#include <sqltypes.h>
#include <sqlucode.h>

#include <limits>

#include <gmock/gmock.h>
#include <gtest/gtest.h>

namespace arrow::flight::sql::odbc {

template <typename T>
class StatementTest : public T {};

class StatementMockTest : public FlightSQLODBCMockTestBase {};
class StatementRemoteTest : public FlightSQLODBCRemoteTestBase {};
using TestTypes = ::testing::Types<StatementMockTest, StatementRemoteTest>;
TYPED_TEST_SUITE(StatementTest, TestTypes);

TYPED_TEST(StatementTest, TestSQLCloseCursor) {
std::wstring wsql = L"SELECT 1;";
std::vector<SQLWCHAR> sql0(wsql.begin(), wsql.end());

ASSERT_EQ(SQL_SUCCESS,
SQLExecDirect(this->stmt, &sql0[0], static_cast<SQLINTEGER>(sql0.size())));

ASSERT_EQ(SQL_SUCCESS, SQLCloseCursor(this->stmt));
}

TYPED_TEST(StatementTest, TestSQLFreeStmtSQLCloseWithoutCursor) {
// Verify SQLFreeStmt(SQL_CLOSE) does not throw error with invalid cursor

ASSERT_EQ(SQL_SUCCESS, SQLFreeStmt(this->stmt, SQL_CLOSE));
}

TYPED_TEST(StatementTest, TestSQLCloseCursorWithoutCursor) {
ASSERT_EQ(SQL_ERROR, SQLCloseCursor(this->stmt));

// Verify invalid cursor error state is returned
VerifyOdbcErrorState(SQL_HANDLE_STMT, this->stmt, kErrorState24000);
}

} // namespace arrow::flight::sql::odbc
Loading