|
| 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 | + |
| 18 | +#include <gtest/gtest.h> |
| 19 | + |
| 20 | +#include "arrow/flight/sql/odbc/odbc_impl/platform.h" |
| 21 | + |
| 22 | +#include "arrow/compute/api.h" // -AL- attempt to keep registry alive |
| 23 | + |
| 24 | +#include <sql.h> |
| 25 | +#include <sqlucode.h> |
| 26 | + |
| 27 | +#include <iostream> |
| 28 | + |
| 29 | +namespace arrow::flight::sql::odbc { |
| 30 | + |
| 31 | +// -AL- todo update to actual ODBC allocation |
| 32 | +class AlinaTestEnvironment : public ::testing::Environment { |
| 33 | + public: |
| 34 | + void SetUp() override { |
| 35 | + int x = 1; |
| 36 | + // -AL- todo add env_v2 for v2 after global setup/teardown works. |
| 37 | + |
| 38 | + // Allocate an environment handle |
| 39 | + ASSERT_EQ(SQL_SUCCESS, SQLAllocEnv(&env)); |
| 40 | + |
| 41 | + ASSERT_EQ(SQL_SUCCESS, |
| 42 | + SQLSetEnvAttr( |
| 43 | + env, SQL_ATTR_ODBC_VERSION, |
| 44 | + reinterpret_cast<SQLPOINTER>(static_cast<intptr_t>(SQL_OV_ODBC3)), 0)); |
| 45 | + |
| 46 | + // Allocate a connection using alloc handle |
| 47 | + ASSERT_EQ(SQL_SUCCESS, SQLAllocHandle(SQL_HANDLE_DBC, env, &conn)); |
| 48 | + std::cout << "-AL- AlinaTestEnvironment::SetUp\n"; |
| 49 | + } |
| 50 | + |
| 51 | + void TearDown() override { |
| 52 | + |
| 53 | + |
| 54 | + // -AL- this doesn't work |
| 55 | + //// Remove function registry before test exits |
| 56 | + auto reg = arrow::compute::GetFunctionRegistry(); |
| 57 | + reg->ClearFunctioRegistry(); |
| 58 | + // delete reg; |
| 59 | + |
| 60 | + |
| 61 | + int y = 1; |
| 62 | + // Free connection handle |
| 63 | + EXPECT_EQ(SQL_SUCCESS, SQLFreeHandle(SQL_HANDLE_DBC, conn)); |
| 64 | + |
| 65 | + // Free environment handle |
| 66 | + EXPECT_EQ(SQL_SUCCESS, SQLFreeHandle(SQL_HANDLE_ENV, env)); |
| 67 | + std::cout << "-AL- AlinaTestEnvironment::TearDown\n"; |
| 68 | + |
| 69 | + } |
| 70 | + |
| 71 | + SQLHENV getEnvHandle() { return env; } |
| 72 | + |
| 73 | + SQLHDBC getConnHandle() { return conn; } |
| 74 | + |
| 75 | + private: |
| 76 | + /** ODBC Environment. */ |
| 77 | + SQLHENV env = 0; |
| 78 | + |
| 79 | + /** ODBC Connect. */ |
| 80 | + SQLHDBC conn = 0; |
| 81 | +}; |
| 82 | + |
| 83 | +} // namespace arrow::flight::sql::odbc |
0 commit comments