|
| 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, TestSQLExecDirectSimpleQuery) { |
| 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 | + // GH-47713 TODO: Uncomment call to SQLFetch SQLGetData after implementation |
| 48 | + /* |
| 49 | + ASSERT_EQ(SQL_SUCCESS, SQLFetch(this->stmt)); |
| 50 | +
|
| 51 | + SQLINTEGER val; |
| 52 | +
|
| 53 | + ASSERT_EQ(SQL_SUCCESS, SQLGetData(this->stmt, 1, SQL_C_LONG, &val, 0, 0)); |
| 54 | + // Verify 1 is returned |
| 55 | + EXPECT_EQ(1, val); |
| 56 | +
|
| 57 | + ASSERT_EQ(SQL_NO_DATA, SQLFetch(this->stmt)); |
| 58 | +
|
| 59 | + ASSERT_EQ(SQL_ERROR, SQLGetData(this->stmt, 1, SQL_C_LONG, &val, 0, 0)); |
| 60 | + // Invalid cursor state |
| 61 | + VerifyOdbcErrorState(SQL_HANDLE_STMT, this->stmt, kErrorState24000); |
| 62 | + */ |
| 63 | +} |
| 64 | + |
| 65 | +TYPED_TEST(StatementTest, TestSQLExecDirectInvalidQuery) { |
| 66 | + std::wstring wsql = L"SELECT;"; |
| 67 | + std::vector<SQLWCHAR> sql0(wsql.begin(), wsql.end()); |
| 68 | + |
| 69 | + ASSERT_EQ(SQL_ERROR, |
| 70 | + SQLExecDirect(this->stmt, &sql0[0], static_cast<SQLINTEGER>(sql0.size()))); |
| 71 | + // ODBC provides generic error code HY000 to all statement errors |
| 72 | + VerifyOdbcErrorState(SQL_HANDLE_STMT, this->stmt, kErrorStateHY000); |
| 73 | +} |
| 74 | + |
| 75 | +TYPED_TEST(StatementTest, TestSQLExecuteSimpleQuery) { |
| 76 | + std::wstring wsql = L"SELECT 1;"; |
| 77 | + std::vector<SQLWCHAR> sql0(wsql.begin(), wsql.end()); |
| 78 | + |
| 79 | + ASSERT_EQ(SQL_SUCCESS, |
| 80 | + SQLPrepare(this->stmt, &sql0[0], static_cast<SQLINTEGER>(sql0.size()))); |
| 81 | + |
| 82 | + ASSERT_EQ(SQL_SUCCESS, SQLExecute(this->stmt)); |
| 83 | + |
| 84 | + // GH-47713 TODO: Uncomment call to SQLFetch SQLGetData after implementation |
| 85 | + /* |
| 86 | + // Fetch data |
| 87 | + ASSERT_EQ(SQL_SUCCESS, SQLFetch(this->stmt)); |
| 88 | +
|
| 89 | + SQLINTEGER val; |
| 90 | + ASSERT_EQ(SQL_SUCCESS, SQLGetData(this->stmt, 1, SQL_C_LONG, &val, 0, 0)); |
| 91 | +
|
| 92 | + // Verify 1 is returned |
| 93 | + EXPECT_EQ(1, val); |
| 94 | +
|
| 95 | + ASSERT_EQ(SQL_NO_DATA, SQLFetch(this->stmt)); |
| 96 | +
|
| 97 | + ASSERT_EQ(SQL_ERROR, SQLGetData(this->stmt, 1, SQL_C_LONG, &val, 0, 0)); |
| 98 | + // Invalid cursor state |
| 99 | + VerifyOdbcErrorState(SQL_HANDLE_STMT, this->stmt, kErrorState24000); |
| 100 | + */ |
| 101 | +} |
| 102 | + |
| 103 | +TYPED_TEST(StatementTest, TestSQLPrepareInvalidQuery) { |
| 104 | + std::wstring wsql = L"SELECT;"; |
| 105 | + std::vector<SQLWCHAR> sql0(wsql.begin(), wsql.end()); |
| 106 | + |
| 107 | + ASSERT_EQ(SQL_ERROR, |
| 108 | + SQLPrepare(this->stmt, &sql0[0], static_cast<SQLINTEGER>(sql0.size()))); |
| 109 | + // ODBC provides generic error code HY000 to all statement errors |
| 110 | + VerifyOdbcErrorState(SQL_HANDLE_STMT, this->stmt, kErrorStateHY000); |
| 111 | + |
| 112 | + ASSERT_EQ(SQL_ERROR, SQLExecute(this->stmt)); |
| 113 | + // Verify function sequence error state is returned |
| 114 | + VerifyOdbcErrorState(SQL_HANDLE_STMT, this->stmt, kErrorStateHY010); |
| 115 | +} |
| 116 | + |
| 117 | +} // namespace arrow::flight::sql::odbc |
0 commit comments