Skip to content

Commit 0b5d6f1

Browse files
committed
Address kou's comments
- removed unneeded code - moved `mkdir -p "$HOME"/Library/ODBC` - replace macro `CONVERT_UTF8_TO_SQLWCHAR_OR_RETURN` with function `ConvertToSQLWCHAR`
1 parent 0fa6143 commit 0b5d6f1

3 files changed

Lines changed: 20 additions & 28 deletions

File tree

compose.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,6 @@ services:
515515
shm_size: *shm-size
516516
cap_add:
517517
- SYS_ADMIN
518-
devices:
519-
- "/dev/fuse:/dev/fuse"
520518
security_opt:
521519
- apparmor:unconfined
522520
ulimits: *ulimits

cpp/src/arrow/flight/sql/odbc/install/unix/install_odbc.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ case "$(uname)" in
4747
*)
4848
# macOS
4949
USER_ODBCINST_FILE="$HOME/Library/ODBC/odbcinst.ini"
50+
mkdir -p "$HOME"/Library/ODBC
5051
;;
5152
esac
5253

5354
DRIVER_NAME="Apache Arrow Flight SQL ODBC Driver"
5455

55-
mkdir -p "$HOME"/Library/ODBC
56-
5756
touch "$USER_ODBCINST_FILE"
5857

5958
if grep -q "^\[$DRIVER_NAME\]" "$USER_ODBCINST_FILE"; then

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

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,26 @@
2525

2626
#include "arrow/flight/sql/odbc/odbc_impl/encoding_utils.h"
2727

28-
#ifdef __linux__
29-
// Linux driver manager uses utf16string
30-
# define CONVERT_UTF8_TO_SQLWCHAR_OR_RETURN(wvar, var) \
31-
auto wvar##_result = arrow::util::UTF8StringToUTF16(var); \
32-
if (!wvar##_result.status().ok()) { \
33-
PostArrowUtilError(wvar##_result.status()); \
34-
return false; \
35-
} \
36-
std::u16string wvar = wvar##_result.ValueOrDie();
37-
38-
#else
39-
// Windows and macOS
40-
# define CONVERT_UTF8_TO_SQLWCHAR_OR_RETURN(wvar, var) \
41-
auto wvar##_result = arrow::util::UTF8ToWideString(var); \
42-
if (!wvar##_result.status().ok()) { \
43-
PostArrowUtilError(wvar##_result.status()); \
44-
return false; \
45-
} \
46-
std::wstring wvar = wvar##_result.ValueOrDie();
47-
#endif // __linux__
48-
4928
namespace arrow::flight::sql::odbc {
5029

5130
using config::Configuration;
5231

32+
#ifdef __linux__
33+
// Linux driver manager uses utf16string
34+
std::u16string ConvertToSQLWCHAR(const std::string_view var) {
35+
auto result = arrow::util::UTF8StringToUTF16(var);
36+
#else
37+
std::wstring ConvertToSQLWCHAR(const std::string_view var) {
38+
// Windows and macOS
39+
auto result = arrow::util::UTF8ToWideString(var);
40+
#endif
41+
if (!result.status().ok()) {
42+
PostArrowUtilError(result.status());
43+
return {}; // return empty string on error
44+
}
45+
return result.ValueOrDie();
46+
}
47+
5348
void PostError(DWORD error_code, LPWSTR error_msg) {
5449
#if defined _WIN32
5550
MessageBox(NULL, error_msg, L"Error!", MB_ICONEXCLAMATION | MB_OK);
@@ -118,7 +113,7 @@ bool UnregisterDsn(const std::wstring& dsn) {
118113
*/
119114
bool RegisterDsn(const Configuration& config, LPCWSTR driver) {
120115
const std::string& dsn = config.Get(FlightSqlConnection::DSN);
121-
CONVERT_UTF8_TO_SQLWCHAR_OR_RETURN(wdsn, dsn);
116+
auto wdsn = ConvertToSQLWCHAR(dsn);
122117

123118
if (!SQLWriteDSNToIni(reinterpret_cast<LPCWSTR>(wdsn.c_str()), driver)) {
124119
PostLastInstallerError();
@@ -133,8 +128,8 @@ bool RegisterDsn(const Configuration& config, LPCWSTR driver) {
133128
continue;
134129
}
135130

136-
CONVERT_UTF8_TO_SQLWCHAR_OR_RETURN(wkey, key);
137-
CONVERT_UTF8_TO_SQLWCHAR_OR_RETURN(wvalue, it->second);
131+
auto wkey = ConvertToSQLWCHAR(key);
132+
auto wvalue = ConvertToSQLWCHAR(it->second);
138133

139134
if (!SQLWritePrivateProfileString(reinterpret_cast<LPCWSTR>(wdsn.c_str()),
140135
reinterpret_cast<LPCWSTR>(wkey.c_str()),

0 commit comments

Comments
 (0)