Skip to content

Commit 1653d29

Browse files
justing-bqrscalesalinaliBQ
committed
Establish ODBC tests
Co-Authored-By: rscales <[email protected]> Co-Authored-By: justing-bq <[email protected]> Co-Authored-By: alinalibq <[email protected]>
1 parent 7a38744 commit 1653d29

File tree

8 files changed

+948
-7
lines changed

8 files changed

+948
-7
lines changed

cpp/src/arrow/flight/sql/odbc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ else()
3434
endif()
3535

3636
add_subdirectory(odbc_impl)
37+
add_subdirectory(tests)
3738

3839
arrow_install_all_headers("arrow/flight/sql/odbc")
3940

cpp/src/arrow/flight/sql/odbc/odbc_impl/encoding_utils.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace ODBC {
3636
using arrow::flight::sql::odbc::DriverException;
3737
using arrow::flight::sql::odbc::GetSqlWCharSize;
3838
using arrow::flight::sql::odbc::Utf8ToWcs;
39+
using arrow::flight::sql::odbc::WcsToUtf8;
3940

4041
// Return the number of bytes required for the conversion.
4142
template <typename CHAR_TYPE>
@@ -80,4 +81,24 @@ inline size_t ConvertToSqlWChar(const std::string& str, SQLWCHAR* buffer,
8081
}
8182
}
8283

84+
/// \brief Convert buffer of SqlWchar to standard string
85+
/// \param[in] wchar_msg SqlWchar to convert
86+
/// \param[in] msg_len Number of characters in wchar_msg
87+
/// \return wchar_msg in std::string format
88+
inline std::string SqlWcharToString(SQLWCHAR* wchar_msg, SQLINTEGER msg_len = SQL_NTS) {
89+
if (msg_len == 0 || !wchar_msg || wchar_msg[0] == 0) {
90+
return std::string();
91+
}
92+
93+
thread_local std::vector<uint8_t> utf8_str;
94+
95+
if (msg_len == SQL_NTS) {
96+
WcsToUtf8((void*)wchar_msg, &utf8_str);
97+
} else {
98+
WcsToUtf8((void*)wchar_msg, msg_len, &utf8_str);
99+
}
100+
101+
return std::string(utf8_str.begin(), utf8_str.end());
102+
}
103+
83104
} // namespace ODBC

cpp/src/arrow/flight/sql/odbc/odbc_impl/system_dsn.cc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
#include "arrow/flight/sql/odbc/odbc_impl/system_dsn.h"
19+
1820
// platform.h includes windows.h, so it needs to be included
1921
// before winuser.h
2022
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"
@@ -33,13 +35,13 @@
3335
#include <odbcinst.h>
3436
#include <sstream>
3537

36-
using arrow::flight::sql::odbc::DriverException;
37-
using arrow::flight::sql::odbc::FlightSqlConnection;
38-
using arrow::flight::sql::odbc::config::Configuration;
39-
using arrow::flight::sql::odbc::config::ConnectionStringParser;
40-
using arrow::flight::sql::odbc::config::DsnConfigurationWindow;
41-
using arrow::flight::sql::odbc::config::Result;
42-
using arrow::flight::sql::odbc::config::Window;
38+
namespace arrow::flight::sql::odbc {
39+
40+
using config::Configuration;
41+
using config::ConnectionStringParser;
42+
using config::DsnConfigurationWindow;
43+
using config::Result;
44+
using config::Window;
4345

4446
bool DisplayConnectionWindow(void* window_parent, Configuration& config) {
4547
HWND hwnd_parent = (HWND)window_parent;
@@ -237,3 +239,5 @@ BOOL INSTAPI ConfigDSNW(HWND hwnd_parent, WORD req, LPCWSTR wdriver,
237239

238240
return TRUE;
239241
}
242+
243+
} // namespace arrow::flight::sql::odbc
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
// platform.h includes windows.h, so it needs to be included first
19+
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"
20+
21+
#include "arrow/flight/sql/odbc/odbc_impl/config/configuration.h"
22+
23+
namespace arrow::flight::sql::odbc {
24+
25+
using config::Configuration;
26+
27+
#if defined _WIN32
28+
/**
29+
* Display connection window for user to configure connection parameters.
30+
*
31+
* @param window_parent Parent window handle.
32+
* @param config Output configuration.
33+
* @return True on success and false on fail.
34+
*/
35+
bool DisplayConnectionWindow(void* window_parent, Configuration& config);
36+
37+
/**
38+
* For SQLDriverConnect.
39+
* Display connection window for user to configure connection parameters.
40+
*
41+
* @param window_parent Parent window handle.
42+
* @param config Output configuration, presumed to be empty, it will be using values from
43+
* properties.
44+
* @param properties Output properties.
45+
* @return True on success and false on fail.
46+
*/
47+
bool DisplayConnectionWindow(void* window_parent, Configuration& config,
48+
Connection::ConnPropertyMap& properties);
49+
#endif
50+
51+
/**
52+
* Register DSN with specified configuration.
53+
*
54+
* @param config Configuration.
55+
* @param driver Driver.
56+
* @return True on success and false on fail.
57+
*/
58+
bool RegisterDsn(const Configuration& config, LPCWSTR driver);
59+
60+
/**
61+
* Unregister specified DSN.
62+
*
63+
* @param dsn DSN name.
64+
* @return True on success and false on fail.
65+
*/
66+
bool UnregisterDsn(const std::wstring& dsn);
67+
68+
} // namespace arrow::flight::sql::odbc
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
add_custom_target(tests)
19+
20+
find_package(ODBC REQUIRED)
21+
include_directories(${ODBC_INCLUDE_DIRS})
22+
23+
find_package(SQLite3Alt REQUIRED)
24+
25+
set(ARROW_FLIGHT_SQL_MOCK_SERVER_SRCS
26+
../../example/sqlite_sql_info.cc
27+
../../example/sqlite_type_info.cc
28+
../../example/sqlite_statement.cc
29+
../../example/sqlite_statement_batch_reader.cc
30+
../../example/sqlite_server.cc
31+
../../example/sqlite_tables_schema_batch_reader.cc)
32+
33+
add_arrow_test(flight_sql_odbc_test
34+
SOURCES
35+
odbc_test_suite.cc
36+
odbc_test_suite.h
37+
connection_test.cc
38+
# Enable Protobuf cleanup after test execution
39+
# GH-46889: move protobuf_test_util to a more common location
40+
../../../../engine/substrait/protobuf_test_util.cc
41+
${ARROW_FLIGHT_SQL_MOCK_SERVER_SRCS}
42+
EXTRA_LINK_LIBS
43+
${ODBC_LIBRARIES}
44+
${ODBCINST}
45+
${SQLite3_LIBRARIES}
46+
arrow_odbc_spi_impl)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
#ifdef _WIN32
19+
# include <windows.h>
20+
#endif
21+
22+
#include <sql.h>
23+
#include <sqltypes.h>
24+
#include <sqlucode.h>
25+
26+
#include "gmock/gmock.h"
27+
#include "gtest/gtest.h"
28+
29+
namespace arrow::flight::sql::odbc {
30+
31+
TEST(SQLAllocHandle, SQLAllocHandleEnv) {
32+
// Allocate an environment handle
33+
SQLHENV env = nullptr;
34+
ASSERT_EQ(SQL_SUCCESS, SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env));
35+
36+
// Check for valid handle
37+
ASSERT_NE(nullptr, env);
38+
39+
// Free an environment handle
40+
ASSERT_EQ(SQL_SUCCESS, SQLFreeHandle(SQL_HANDLE_ENV, env));
41+
}
42+
43+
} // namespace arrow::flight::sql::odbc

0 commit comments

Comments
 (0)