|
| 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, SQLNumResultColsReturnsColumnsOnSelect) { |
| 41 | + SQLSMALLINT column_count = 0; |
| 42 | + SQLSMALLINT expected_value = 3; |
| 43 | + SQLWCHAR sql_query[] = L"SELECT 1 AS col1, 'One' AS col2, 3 AS col3"; |
| 44 | + SQLINTEGER query_length = static_cast<SQLINTEGER>(wcslen(sql_query)); |
| 45 | + |
| 46 | + ASSERT_EQ(SQL_SUCCESS, SQLExecDirect(this->stmt, sql_query, query_length)); |
| 47 | + |
| 48 | + ASSERT_EQ(SQL_SUCCESS, SQLFetch(this->stmt)); |
| 49 | + |
| 50 | + CheckIntColumn(this->stmt, 1, 1); |
| 51 | + CheckStringColumnW(this->stmt, 2, L"One"); |
| 52 | + CheckIntColumn(this->stmt, 3, 3); |
| 53 | + |
| 54 | + ASSERT_EQ(SQL_SUCCESS, SQLNumResultCols(this->stmt, &column_count)); |
| 55 | + |
| 56 | + EXPECT_EQ(expected_value, column_count); |
| 57 | +} |
| 58 | + |
| 59 | +TYPED_TEST(StatementTest, SQLNumResultColsReturnsSuccessOnNullptr) { |
| 60 | + SQLWCHAR sql_query[] = L"SELECT 1 AS col1, 'One' AS col2, 3 AS col3"; |
| 61 | + SQLINTEGER query_length = static_cast<SQLINTEGER>(wcslen(sql_query)); |
| 62 | + |
| 63 | + ASSERT_EQ(SQL_SUCCESS, SQLExecDirect(this->stmt, sql_query, query_length)); |
| 64 | + |
| 65 | + ASSERT_EQ(SQL_SUCCESS, SQLFetch(this->stmt)); |
| 66 | + |
| 67 | + CheckIntColumn(this->stmt, 1, 1); |
| 68 | + CheckStringColumnW(this->stmt, 2, L"One"); |
| 69 | + CheckIntColumn(this->stmt, 3, 3); |
| 70 | + |
| 71 | + ASSERT_EQ(SQL_SUCCESS, SQLNumResultCols(this->stmt, nullptr)); |
| 72 | +} |
| 73 | + |
| 74 | +TYPED_TEST(StatementTest, SQLNumResultColsFunctionSequenceErrorOnNoQuery) { |
| 75 | + SQLSMALLINT column_count = 0; |
| 76 | + SQLSMALLINT expected_value = 0; |
| 77 | + |
| 78 | + ASSERT_EQ(SQL_ERROR, SQLNumResultCols(this->stmt, &column_count)); |
| 79 | + VerifyOdbcErrorState(SQL_HANDLE_STMT, this->stmt, kErrorStateHY010); |
| 80 | + |
| 81 | + EXPECT_EQ(expected_value, column_count); |
| 82 | +} |
| 83 | + |
| 84 | +} // namespace arrow::flight::sql::odbc |
0 commit comments