Skip to content

Commit 03522a0

Browse files
committed
Implement system_dsn for Mac
1 parent 3556804 commit 03522a0

6 files changed

Lines changed: 13 additions & 21 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ add_library(arrow_odbc_spi_impl
109109
types.h
110110
type_fwd.h
111111
type_utilities.h
112+
system_dsn.cc
113+
system_dsn.h
112114
util.cc
113115
util.h)
114116
target_compile_definitions(arrow_odbc_spi_impl PUBLIC UNICODE)
@@ -125,9 +127,7 @@ if(WIN32)
125127
ui/dsn_configuration_window.h
126128
ui/window.cc
127129
ui/window.h
128-
win_system_dsn.cc
129-
system_dsn.cc
130-
system_dsn.h)
130+
win_system_dsn.cc)
131131
endif()
132132

133133
if(APPLE)

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,19 @@
1717

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

20-
#include "arrow/flight/sql/odbc/odbc_impl/config/configuration.h"
21-
#include "arrow/flight/sql/odbc/odbc_impl/flight_sql_connection.h"
22-
#include "arrow/flight/sql/odbc/odbc_impl/ui/dsn_configuration_window.h"
23-
#include "arrow/flight/sql/odbc/odbc_impl/ui/window.h"
24-
#include "arrow/flight/sql/odbc/odbc_impl/util.h"
2520
#include "arrow/result.h"
2621
#include "arrow/util/utf8.h"
2722

28-
#include <odbcinst.h>
2923
#include <sstream>
3024

3125
namespace arrow::flight::sql::odbc {
3226

3327
using config::Configuration;
3428

35-
void PostError(DWORD error_code, LPCWSTR error_msg) {
29+
void PostError(DWORD error_code, LPWSTR error_msg) {
30+
#if defined _WIN32
3631
MessageBox(NULL, error_msg, L"Error!", MB_ICONEXCLAMATION | MB_OK);
32+
#endif // _WIN32
3733
SQLPostInstallerError(error_code, error_msg);
3834
}
3935

@@ -42,7 +38,7 @@ void PostArrowUtilError(arrow::Status error_status) {
4238
std::wstring werror_msg = arrow::util::UTF8ToWideString(error_msg).ValueOr(
4339
L"Error during utf8 to wide string conversion");
4440

45-
PostError(ODBC_ERROR_GENERAL_ERR, werror_msg.c_str());
41+
PostError(ODBC_ERROR_GENERAL_ERR, (LPWSTR)werror_msg.c_str());
4642
}
4743

4844
void PostLastInstallerError() {
@@ -55,7 +51,7 @@ void PostLastInstallerError() {
5551
buf << L"Message: \"" << msg << L"\", Code: " << code;
5652
std::wstring error_msg = buf.str();
5753

58-
PostError(code, error_msg.c_str());
54+
PostError(code, (LPWSTR)error_msg.c_str());
5955
}
6056

6157
/**

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"
2020

2121
#include "arrow/flight/sql/odbc/odbc_impl/config/configuration.h"
22+
#include "arrow/flight/sql/odbc/odbc_impl/flight_sql_connection.h"
2223
#include "arrow/status.h"
2324

25+
#include <odbcinst.h>
26+
2427
namespace arrow::flight::sql::odbc {
2528

2629
#if defined _WIN32
@@ -64,7 +67,7 @@ bool RegisterDsn(const config::Configuration& config, LPCWSTR driver);
6467
*/
6568
bool UnregisterDsn(const std::wstring& dsn);
6669

67-
void PostError(DWORD error_code, LPCWSTR error_msg);
70+
void PostError(DWORD error_code, LPWSTR error_msg);
6871

6972
void PostArrowUtilError(arrow::Status error_status);
7073
} // namespace arrow::flight::sql::odbc

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ BOOL INSTAPI ConfigDSNW(HWND hwnd_parent, WORD req, LPCWSTR wdriver,
144144
std::wstring werror_msg =
145145
arrow::util::UTF8ToWideString(error_msg).ValueOr(L"Error during DSN load");
146146

147-
PostError(err.GetNativeError(), werror_msg.c_str());
147+
PostError(err.GetNativeError(), (LPWSTR)werror_msg.c_str());
148148
return FALSE;
149149
}
150150

cpp/src/arrow/flight/sql/odbc/tests/connection_test.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ TYPED_TEST(ConnectionHandleTest, TestSQLDriverConnect) {
248248
<< GetOdbcErrorMessage(SQL_HANDLE_DBC, this->conn);
249249
}
250250

251-
#if defined _WIN32
252251
TYPED_TEST(ConnectionHandleTest, TestSQLDriverConnectDsn) {
253252
// Connect string
254253
std::string connect_str = this->GetConnectionString();
@@ -432,8 +431,6 @@ TEST_F(ConnectionRemoteTest, TestSQLConnectDSNPrecedence) {
432431
<< GetOdbcErrorMessage(SQL_HANDLE_DBC, conn);
433432
}
434433

435-
#endif // _WIN32
436-
437434
TEST_F(ConnectionRemoteTest, TestSQLDriverConnectInvalidUid) {
438435
// Invalid connect string
439436
std::string connect_str = GetInvalidConnectionString();

cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,6 @@ std::string GetOdbcErrorMessage(SQLSMALLINT handle_type, SQLHANDLE handle) {
463463
return res;
464464
}
465465

466-
// GH-47822 TODO: once RegisterDsn is implemented in Mac and Linux, the following can be
467-
// re-enabled.
468-
#if defined _WIN32
469466
bool WriteDSN(std::string connection_str) {
470467
Connection::ConnPropertyMap properties;
471468

@@ -490,7 +487,6 @@ bool WriteDSN(Connection::ConnPropertyMap properties) {
490487
std::wstring w_driver = arrow::util::UTF8ToWideString(driver).ValueOr(L"");
491488
return RegisterDsn(config, w_driver.c_str());
492489
}
493-
#endif
494490

495491
std::wstring GetStringColumnW(SQLHSTMT stmt, int col_id) {
496492
SQLWCHAR buf[1024];

0 commit comments

Comments
 (0)