Skip to content
Merged
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
4 changes: 2 additions & 2 deletions cpp/cmake_modules/DefineOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ macro(tsort_bool_option_dependencies)
endmacro()

macro(resolve_option_dependencies)
# Arrow Flight SQL ODBC is available only for Windows for now.
if(NOT WIN32)
# Arrow Flight SQL ODBC is available only for Windows and macOS for now.
if(NOT WIN32 AND NOT APPLE)
set(ARROW_FLIGHT_SQL_ODBC OFF)
endif()
if(MSVC_TOOLCHAIN)
Expand Down
18 changes: 9 additions & 9 deletions cpp/src/arrow/flight/sql/odbc/flight_sql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

add_library(arrow_odbc_spi_impl
include/flight_sql/flight_sql_driver.h
include/flight_sql/config/configuration.h
include/flight_sql/config/connection_string_parser.h
accessors/binary_array_accessor.cc
accessors/binary_array_accessor.h
accessors/boolean_array_accessor.cc
Expand Down Expand Up @@ -76,8 +78,8 @@ add_library(arrow_odbc_spi_impl
scalar_function_reporter.h
system_trust_store.cc
system_trust_store.h
system_dsn.cc
system_dsn.h
config/configuration.cc
config/connection_string_parser.cc
utils.cc)
target_include_directories(arrow_odbc_spi_impl
PUBLIC include include/flight_sql
Expand All @@ -86,26 +88,24 @@ target_include_directories(arrow_odbc_spi_impl PUBLIC ${CMAKE_CURRENT_LIST_DIR})

if(WIN32)
target_sources(arrow_odbc_spi_impl
PRIVATE include/flight_sql/config/configuration.h
include/flight_sql/config/connection_string_parser.h
include/flight_sql/ui/add_property_window.h
PRIVATE include/flight_sql/ui/add_property_window.h
include/flight_sql/ui/custom_window.h
include/flight_sql/ui/dsn_configuration_window.h
include/flight_sql/ui/window.h
config/configuration.cc
config/connection_string_parser.cc
ui/custom_window.cc
ui/window.cc
ui/dsn_configuration_window.cc
ui/add_property_window.cc
win_system_dsn.cc)
win_system_dsn.cc
system_dsn.cc
system_dsn.h)
endif()

target_link_libraries(arrow_odbc_spi_impl PUBLIC odbcabstraction arrow_flight_sql_shared
arrow_compute_shared Boost::locale)

# Link libraries on MINGW64 only
if(MINGW AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if((MINGW AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR APPLE)
target_link_libraries(arrow_odbc_spi_impl PUBLIC ${ODBCINST})
endif()

Expand Down
3 changes: 2 additions & 1 deletion cpp/src/arrow/flight/sql/odbc/flight_sql/address_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// under the License.

#include "arrow/flight/sql/odbc/flight_sql/address_info.h"
#include <cstdint>

namespace driver {

Expand All @@ -34,7 +35,7 @@ bool AddressInfo::GetAddressInfo(const std::string& host, char* host_name_info,
}

error = getnameinfo(addrinfo_result_->ai_addr, addrinfo_result_->ai_addrlen,
host_name_info, static_cast<DWORD>(max_host), NULL, 0, 0);
host_name_info, static_cast<uint32_t>(max_host), NULL, 0, 0);
return error == 0;
Comment thread
alinaliBQ marked this conversation as resolved.
Outdated
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/platform.h"
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/spi/connection.h"

#if defined _WIN32 || defined _WIN64
// winuser.h needs to be included after windows.h, which is defined in platform.h
#include <winuser.h>
# include <winuser.h>
#endif

namespace driver {
namespace flight_sql {
namespace config {
Expand Down
18 changes: 9 additions & 9 deletions cpp/src/arrow/flight/sql/odbc/tests/columns_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2333,7 +2333,7 @@ TEST_F(FlightSQLODBCMockTestBase, SQLDescribeColValidateInput) {
SQLUSMALLINT outOfRangeColumn = 4;
SQLUSMALLINT negativeColumn = -1;
SQLWCHAR columnName[1024];
constexpr SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
Comment thread
alinaliBQ marked this conversation as resolved.
Outdated
SQLSMALLINT nameLength = 0;
SQLSMALLINT dataType = 0;
SQLULEN columnSize = 0;
Expand Down Expand Up @@ -2378,7 +2378,7 @@ TEST_F(FlightSQLODBCMockTestBase, SQLDescribeColQueryAllDataTypesMetadata) {
this->connect();

SQLWCHAR columnName[1024];
constexpr SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
SQLSMALLINT nameLength = 0;
SQLSMALLINT columnDataType = 0;
SQLULEN columnSize = 0;
Expand Down Expand Up @@ -2454,7 +2454,7 @@ TEST_F(FlightSQLODBCRemoteTestBase, SQLDescribeColQueryAllDataTypesMetadata) {
this->connect();

SQLWCHAR columnName[1024];
constexpr SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
SQLSMALLINT nameLength = 0;
SQLSMALLINT columnDataType = 0;
SQLULEN columnSize = 0;
Expand Down Expand Up @@ -2537,7 +2537,7 @@ TEST_F(FlightSQLODBCRemoteTestBase, SQLDescribeColODBCTestTableMetadata) {
this->connect();

SQLWCHAR columnName[1024];
constexpr SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
SQLSMALLINT nameLength = 0;
SQLSMALLINT columnDataType = 0;
SQLULEN columnSize = 0;
Expand Down Expand Up @@ -2599,7 +2599,7 @@ TEST_F(FlightSQLODBCRemoteTestBase, SQLDescribeColODBCTestTableMetadataODBC2) {
this->connect(SQL_OV_ODBC2);

SQLWCHAR columnName[1024];
constexpr SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
SQLSMALLINT nameLength = 0;
SQLSMALLINT columnDataType = 0;
SQLULEN columnSize = 0;
Expand Down Expand Up @@ -2661,7 +2661,7 @@ TEST_F(FlightSQLODBCMockTestBase, SQLDescribeColAllTypesTableMetadata) {
this->CreateTableAllDataType();

SQLWCHAR columnName[1024];
constexpr SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
SQLSMALLINT nameLength = 0;
SQLSMALLINT columnDataType = 0;
SQLULEN columnSize = 0;
Expand Down Expand Up @@ -2717,7 +2717,7 @@ TEST_F(FlightSQLODBCMockTestBase, SQLDescribeColUnicodeTableMetadata) {
this->CreateUnicodeTable();

SQLWCHAR columnName[1024];
constexpr SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
SQLSMALLINT nameLength = 0;
SQLSMALLINT columnDataType = 0;
SQLULEN columnSize = 0;
Expand Down Expand Up @@ -2761,7 +2761,7 @@ TYPED_TEST(FlightSQLODBCTestBase, SQLColumnsGetMetadataBySQLDescribeCol) {
this->connect();

SQLWCHAR columnName[1024];
constexpr SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
SQLSMALLINT nameLength = 0;
SQLSMALLINT columnDataType = 0;
SQLULEN columnSize = 0;
Expand Down Expand Up @@ -2821,7 +2821,7 @@ TYPED_TEST(FlightSQLODBCTestBase, SQLColumnsGetMetadataBySQLDescribeColODBC2) {
this->connect(SQL_OV_ODBC2);

SQLWCHAR columnName[1024];
constexpr SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
SQLINTEGER bufCharLen = sizeof(columnName) / ODBC::GetSqlWCharSize();
SQLSMALLINT nameLength = 0;
SQLSMALLINT columnDataType = 0;
SQLULEN columnSize = 0;
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/tests/connection_info_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoDataSourceName) {
this->disconnect();
}

#ifdef SQL_DRIVER_AWARE_POOLING_SUPPORTED
TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoDriverAwarePoolingSupported) {
// A driver does not need to implement SQL_DRIVER_AWARE_POOLING_SUPPORTED and the
// Driver Manager will not honor to the driver's return value.
Expand All @@ -197,6 +198,7 @@ TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoDriverAwarePoolingSupported) {

this->disconnect();
}
#endif

// These information types are implemented by the Driver Manager alone.
TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoDriverHdbc) {
Expand Down
107 changes: 55 additions & 52 deletions cpp/src/arrow/flight/sql/odbc/tests/connection_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ TYPED_TEST(FlightSQLODBCTestBase, TestSQLDriverConnect) {
EXPECT_EQ(ret, SQL_SUCCESS);
}

#if defined _WIN32 || defined _WIN64
TYPED_TEST(FlightSQLODBCTestBase, TestSQLDriverConnectDsn) {
// ODBC Environment
SQLHENV env;
Expand Down Expand Up @@ -452,58 +453,6 @@ TYPED_TEST(FlightSQLODBCTestBase, TestSQLDriverConnectDsn) {
EXPECT_EQ(ret, SQL_SUCCESS);
}

TEST_F(FlightSQLODBCRemoteTestBase, TestSQLDriverConnectInvalidUid) {
// ODBC Environment
SQLHENV env;
SQLHDBC conn;

// Allocate an environment handle
SQLRETURN ret = SQLAllocEnv(&env);

EXPECT_EQ(ret, SQL_SUCCESS);

ret = SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);

EXPECT_EQ(ret, SQL_SUCCESS);

// Allocate a connection using alloc handle
ret = SQLAllocHandle(SQL_HANDLE_DBC, env, &conn);

EXPECT_EQ(ret, SQL_SUCCESS);

// Invalid connect string
std::string connect_str = getInvalidConnectionString();

ASSERT_OK_AND_ASSIGN(std::wstring wconnect_str,
arrow::util::UTF8ToWideString(connect_str));
std::vector<SQLWCHAR> connect_str0(wconnect_str.begin(), wconnect_str.end());

SQLWCHAR outstr[ODBC_BUFFER_SIZE];
SQLSMALLINT outstrlen;

// Connecting to ODBC server.
ret = SQLDriverConnect(conn, NULL, &connect_str0[0],
static_cast<SQLSMALLINT>(connect_str0.size()), outstr,
ODBC_BUFFER_SIZE, &outstrlen, SQL_DRIVER_NOPROMPT);

EXPECT_TRUE(ret == SQL_ERROR);

VerifyOdbcErrorState(SQL_HANDLE_DBC, conn, error_state_28000);

std::string out_connection_string = ODBC::SqlWcharToString(outstr, outstrlen);
EXPECT_TRUE(out_connection_string.empty());

// Free connection handle
ret = SQLFreeHandle(SQL_HANDLE_DBC, conn);

EXPECT_EQ(ret, SQL_SUCCESS);

// Free environment handle
ret = SQLFreeHandle(SQL_HANDLE_ENV, env);

EXPECT_EQ(ret, SQL_SUCCESS);
}

TYPED_TEST(FlightSQLODBCTestBase, TestSQLConnect) {
// ODBC Environment
SQLHENV env;
Expand Down Expand Up @@ -791,6 +740,60 @@ TEST_F(FlightSQLODBCRemoteTestBase, TestSQLConnectDSNPrecedence) {
EXPECT_EQ(ret, SQL_SUCCESS);
}

#endif

TEST_F(FlightSQLODBCRemoteTestBase, TestSQLDriverConnectInvalidUid) {
// ODBC Environment
SQLHENV env;
SQLHDBC conn;

// Allocate an environment handle
SQLRETURN ret = SQLAllocEnv(&env);

EXPECT_EQ(ret, SQL_SUCCESS);

ret = SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);

EXPECT_EQ(ret, SQL_SUCCESS);

// Allocate a connection using alloc handle
ret = SQLAllocHandle(SQL_HANDLE_DBC, env, &conn);

EXPECT_EQ(ret, SQL_SUCCESS);

// Invalid connect string
std::string connect_str = getInvalidConnectionString();

ASSERT_OK_AND_ASSIGN(std::wstring wconnect_str,
arrow::util::UTF8ToWideString(connect_str));
std::vector<SQLWCHAR> connect_str0(wconnect_str.begin(), wconnect_str.end());

SQLWCHAR outstr[ODBC_BUFFER_SIZE];
SQLSMALLINT outstrlen;

// Connecting to ODBC server.
ret = SQLDriverConnect(conn, NULL, &connect_str0[0],
static_cast<SQLSMALLINT>(connect_str0.size()), outstr,
ODBC_BUFFER_SIZE, &outstrlen, SQL_DRIVER_NOPROMPT);

EXPECT_TRUE(ret == SQL_ERROR);

VerifyOdbcErrorState(SQL_HANDLE_DBC, conn, error_state_28000);

std::string out_connection_string = ODBC::SqlWcharToString(outstr, outstrlen);
EXPECT_TRUE(out_connection_string.empty());

// Free connection handle
ret = SQLFreeHandle(SQL_HANDLE_DBC, conn);

EXPECT_EQ(ret, SQL_SUCCESS);

// Free environment handle
ret = SQLFreeHandle(SQL_HANDLE_ENV, env);

EXPECT_EQ(ret, SQL_SUCCESS);
}

TEST(SQLDisconnect, TestSQLDisconnectWithoutConnection) {
// ODBC Environment
SQLHENV env;
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@ std::string GetOdbcErrorMessage(SQLSMALLINT handle_type, SQLHANDLE handle) {
return res;
}

// TODO: once RegisterDsn is implemented in Mac and Linux, the following can be
// re-enabled.
#if defined _WIN32 || defined _WIN64
Comment thread
alinaliBQ marked this conversation as resolved.
Outdated
bool writeDSN(std::string connection_str) {
Connection::ConnPropertyMap properties;

Expand All @@ -420,6 +423,7 @@ bool writeDSN(Connection::ConnPropertyMap properties) {
std::wstring wDriver = arrow::util::UTF8ToWideString(driver).ValueOr(L"");
return RegisterDsn(config, wDriver.c_str());
}
#endif

std::wstring ConvertToWString(const std::vector<SQLWCHAR>& strVal, SQLSMALLINT strLen) {
std::wstring attrStr;
Expand Down
Loading