Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/src/arrow/flight/sql/odbc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ else()
endif()

add_subdirectory(odbc_impl)
add_subdirectory(tests)

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

Expand Down
21 changes: 21 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/odbc_impl/encoding_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace ODBC {
using arrow::flight::sql::odbc::DriverException;
using arrow::flight::sql::odbc::GetSqlWCharSize;
using arrow::flight::sql::odbc::Utf8ToWcs;
using arrow::flight::sql::odbc::WcsToUtf8;

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

/// \brief Convert buffer of SqlWchar to standard string
/// \param[in] wchar_msg SqlWchar to convert
/// \param[in] msg_len Number of characters in wchar_msg
/// \return wchar_msg in std::string format
inline std::string SqlWcharToString(SQLWCHAR* wchar_msg, SQLINTEGER msg_len = SQL_NTS) {
if (msg_len == 0 || !wchar_msg || wchar_msg[0] == 0) {
return std::string();
}

thread_local std::vector<uint8_t> utf8_str;

if (msg_len == SQL_NTS) {
WcsToUtf8((void*)wchar_msg, &utf8_str);
} else {
WcsToUtf8((void*)wchar_msg, msg_len, &utf8_str);
}

return std::string(utf8_str.begin(), utf8_str.end());
}

} // namespace ODBC
18 changes: 11 additions & 7 deletions cpp/src/arrow/flight/sql/odbc/odbc_impl/system_dsn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

#include "arrow/flight/sql/odbc/odbc_impl/system_dsn.h"

// platform.h includes windows.h, so it needs to be included
// before winuser.h
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"
Expand All @@ -33,13 +35,13 @@
#include <odbcinst.h>
#include <sstream>

using arrow::flight::sql::odbc::DriverException;
using arrow::flight::sql::odbc::FlightSqlConnection;
using arrow::flight::sql::odbc::config::Configuration;
using arrow::flight::sql::odbc::config::ConnectionStringParser;
using arrow::flight::sql::odbc::config::DsnConfigurationWindow;
using arrow::flight::sql::odbc::config::Result;
using arrow::flight::sql::odbc::config::Window;
namespace arrow::flight::sql::odbc {

using config::Configuration;
using config::ConnectionStringParser;
using config::DsnConfigurationWindow;
using config::Result;
using config::Window;

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

return TRUE;
}

} // namespace arrow::flight::sql::odbc
68 changes: 68 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/odbc_impl/system_dsn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

// platform.h includes windows.h, so it needs to be included first
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"

#include "arrow/flight/sql/odbc/odbc_impl/config/configuration.h"

namespace arrow::flight::sql::odbc {

using config::Configuration;

#if defined _WIN32 || defined _WIN64
/**
* Display connection window for user to configure connection parameters.
*
* @param window_parent Parent window handle.
* @param config Output configuration.
* @return True on success and false on fail.
*/
bool DisplayConnectionWindow(void* window_parent, Configuration& config);

/**
* For SQLDriverConnect.
* Display connection window for user to configure connection parameters.
*
* @param window_parent Parent window handle.
* @param config Output configuration, presumed to be empty, it will be using values from
* properties.
* @param properties Output properties.
* @return True on success and false on fail.
*/
bool DisplayConnectionWindow(void* window_parent, Configuration& config,
Connection::ConnPropertyMap& properties);
#endif

/**
* Register DSN with specified configuration.
*
* @param config Configuration.
* @param driver Driver.
* @return True on success and false on fail.
*/
bool RegisterDsn(const Configuration& config, LPCWSTR driver);

/**
* Unregister specified DSN.
*
* @param dsn DSN name.
* @return True on success and false on fail.
*/
bool UnregisterDsn(const std::wstring& dsn);

} // namespace arrow::flight::sql::odbc
46 changes: 46 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

add_custom_target(tests)

find_package(ODBC REQUIRED)
include_directories(${ODBC_INCLUDE_DIRS})

find_package(SQLite3Alt REQUIRED)

set(ARROW_FLIGHT_SQL_MOCK_SERVER_SRCS
../../example/sqlite_sql_info.cc
../../example/sqlite_type_info.cc
../../example/sqlite_statement.cc
../../example/sqlite_statement_batch_reader.cc
../../example/sqlite_server.cc
../../example/sqlite_tables_schema_batch_reader.cc)

add_arrow_test(flight_sql_odbc_test
SOURCES
odbc_test_suite.cc
odbc_test_suite.h
connection_test.cc
# Enable Protobuf cleanup after test execution
# GH-46889: move protobuf_test_util to a more common location
../../../../engine/substrait/protobuf_test_util.cc
${ARROW_FLIGHT_SQL_MOCK_SERVER_SRCS}
EXTRA_LINK_LIBS
${ODBC_LIBRARIES}
${ODBCINST}
${SQLite3_LIBRARIES}
arrow_odbc_spi_impl)
43 changes: 43 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/tests/connection_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#ifdef _WIN32
# include <windows.h>
#endif

#include <sql.h>
#include <sqltypes.h>
#include <sqlucode.h>

#include "gmock/gmock.h"
#include "gtest/gtest.h"

namespace arrow::flight::sql::odbc {

TEST(SQLAllocHandle, SQLAllocHandleEnv) {
// Allocate an environment handle
SQLHENV env = nullptr;
ASSERT_EQ(SQL_SUCCESS, SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env));

// Check for valid handle
ASSERT_NE(nullptr, env);

// Free an environment handle
ASSERT_EQ(SQL_SUCCESS, SQLFreeHandle(SQL_HANDLE_ENV, env));
}

} // namespace arrow::flight::sql::odbc
Loading
Loading