|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | +#include "arrow/flight/sql/odbc/tests/odbc_test_suite.h" |
| 18 | + |
| 19 | +#include "arrow/flight/sql/odbc/odbc_impl/platform.h" |
| 20 | + |
| 21 | +#include <sql.h> |
| 22 | +#include <sqltypes.h> |
| 23 | +#include <sqlucode.h> |
| 24 | + |
| 25 | +#include <limits> |
| 26 | + |
| 27 | +#include <gmock/gmock.h> |
| 28 | +#include <gtest/gtest.h> |
| 29 | + |
| 30 | +namespace arrow::flight::sql::odbc { |
| 31 | + |
| 32 | +template <typename T> |
| 33 | +class StatementTest : public T {}; |
| 34 | + |
| 35 | +class StatementMockTest : public FlightSQLODBCMockTestBase {}; |
| 36 | +class StatementRemoteTest : public FlightSQLODBCRemoteTestBase {}; |
| 37 | +using TestTypes = ::testing::Types<StatementMockTest, StatementRemoteTest>; |
| 38 | +TYPED_TEST_SUITE(StatementTest, TestTypes); |
| 39 | + |
| 40 | +TYPED_TEST(StatementTest, TestSQLCloseCursor) { |
| 41 | + std::wstring wsql = L"SELECT 1;"; |
| 42 | + std::vector<SQLWCHAR> sql0(wsql.begin(), wsql.end()); |
| 43 | + |
| 44 | + ASSERT_EQ(SQL_SUCCESS, |
| 45 | + SQLExecDirect(this->stmt, &sql0[0], static_cast<SQLINTEGER>(sql0.size()))); |
| 46 | + |
| 47 | + ASSERT_EQ(SQL_SUCCESS, SQLCloseCursor(this->stmt)); |
| 48 | +} |
| 49 | + |
| 50 | +TYPED_TEST(StatementTest, TestSQLFreeStmtSQLCloseWithoutCursor) { |
| 51 | + // SQLFreeStmt(SQL_CLOSE) does not throw error with invalid cursor |
| 52 | + |
| 53 | + ASSERT_EQ(SQL_SUCCESS, SQLFreeStmt(this->stmt, SQL_CLOSE)); |
| 54 | +} |
| 55 | + |
| 56 | +TYPED_TEST(StatementTest, TestSQLCloseCursorWithoutCursor) { |
| 57 | + ASSERT_EQ(SQL_ERROR, SQLCloseCursor(this->stmt)); |
| 58 | + |
| 59 | + // Verify invalid cursor error state is returned |
| 60 | + VerifyOdbcErrorState(SQL_HANDLE_STMT, this->stmt, kErrorState24000); |
| 61 | +} |
| 62 | + |
| 63 | +} // namespace arrow::flight::sql::odbc |
0 commit comments