Skip to content

Commit c36a62e

Browse files
committed
In-progress implement unicode support conversion
1 parent 7ff034a commit c36a62e

3 files changed

Lines changed: 52 additions & 22 deletions

File tree

cpp/src/arrow/flight/sql/odbc/odbc_impl/config/configuration.cc

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,20 @@ std::string ReadDsnString(const std::string& dsn, std::string_view key,
6060

6161
#define BUFFER_SIZE (1024)
6262
std::vector<SQLWCHAR> buf(BUFFER_SIZE);
63-
int ret = SQLGetPrivateProfileString(
64-
reinterpret_cast<LPCWSTR>(wdsn.c_str()), reinterpret_cast<LPCWSTR>(wkey.c_str()),
65-
reinterpret_cast<LPCWSTR>(wdflt.c_str()), buf.data(), static_cast<int>(buf.size()),
66-
reinterpret_cast<LPCWSTR>(L"ODBC.INI"));
63+
int ret = SQLGetPrivateProfileString(reinterpret_cast<LPCWSTR>(GET_SQWCHAR_PTR(wdsn)),
64+
reinterpret_cast<LPCWSTR>(GET_SQWCHAR_PTR(wkey)),
65+
reinterpret_cast<LPCWSTR>(GET_SQWCHAR_PTR(wdflt)),
66+
buf.data(), static_cast<int>(buf.size()),
67+
reinterpret_cast<LPCWSTR>(L"ODBC.INI"));
6768

6869
if (ret > BUFFER_SIZE) {
6970
// If there wasn't enough space, try again with the right size buffer.
7071
buf.resize(ret + 1);
71-
ret = SQLGetPrivateProfileString(
72-
reinterpret_cast<LPCWSTR>(wdsn.c_str()), reinterpret_cast<LPCWSTR>(wkey.c_str()),
73-
reinterpret_cast<LPCWSTR>(wdflt.c_str()), buf.data(),
74-
static_cast<int>(buf.size()), reinterpret_cast<LPCWSTR>(L"ODBC.INI"));
72+
ret = SQLGetPrivateProfileString(reinterpret_cast<LPCWSTR>(GET_SQWCHAR_PTR(wdsn)),
73+
reinterpret_cast<LPCWSTR>(GET_SQWCHAR_PTR(wkey)),
74+
reinterpret_cast<LPCWSTR>(GET_SQWCHAR_PTR(wdflt)),
75+
buf.data(), static_cast<int>(buf.size()),
76+
reinterpret_cast<LPCWSTR>(L"ODBC.INI"));
7577
}
7678

7779
std::string result("");
@@ -101,16 +103,18 @@ std::vector<std::string> ReadAllKeys(const std::string& dsn) {
101103

102104
std::vector<SQLWCHAR> buf(BUFFER_SIZE);
103105

104-
int ret = SQLGetPrivateProfileString(
105-
reinterpret_cast<LPCWSTR>(wdsn.c_str()), NULL, reinterpret_cast<LPCWSTR>(L""),
106-
buf.data(), static_cast<int>(buf.size()), reinterpret_cast<LPCWSTR>(L"ODBC.INI"));
106+
int ret = SQLGetPrivateProfileString(reinterpret_cast<LPCWSTR>(GET_SQWCHAR_PTR(wdsn)),
107+
NULL, reinterpret_cast<LPCWSTR>(L""), buf.data(),
108+
static_cast<int>(buf.size()),
109+
reinterpret_cast<LPCWSTR>(L"ODBC.INI"));
107110

108111
if (ret > BUFFER_SIZE) {
109112
// If there wasn't enough space, try again with the right size buffer.
110113
buf.resize(ret + 1);
111-
ret = SQLGetPrivateProfileString(
112-
reinterpret_cast<LPCWSTR>(wdsn.c_str()), NULL, reinterpret_cast<LPCWSTR>(L""),
113-
buf.data(), static_cast<int>(buf.size()), reinterpret_cast<LPCWSTR>(L"ODBC.INI"));
114+
ret = SQLGetPrivateProfileString(reinterpret_cast<LPCWSTR>(GET_SQWCHAR_PTR(wdsn)),
115+
NULL, reinterpret_cast<LPCWSTR>(L""), buf.data(),
116+
static_cast<int>(buf.size()),
117+
reinterpret_cast<LPCWSTR>(L"ODBC.INI"));
114118
}
115119

116120
// When you pass NULL to SQLGetPrivateProfileString it gives back a \0 delimited list of

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,25 @@
2828
#include <memory>
2929
#include <string>
3030

31+
// Workaround for ODBC `BOOL` def conflict on Linux
32+
#ifdef __linux__
33+
# ifdef BOOL
34+
# undef BOOL
35+
# endif // BOOL
36+
#endif // __linux__
37+
#include "arrow/util/utf8.h"
38+
39+
#include "arrow/util/logging.h" // -AL- TEMP
40+
3141
#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
3242

43+
#ifdef __linux__
44+
# define GET_SQWCHAR_PTR(wstring_var) (ODBC::ToSqlWCharVector(wstring_var).data())
45+
#else
46+
// Windows and macOS
47+
# define GET_SQWCHAR_PTR(wstring_var) (wstring_var.c_str())
48+
#endif
49+
3350
namespace ODBC {
3451
using arrow::flight::sql::odbc::DriverException;
3552
using arrow::flight::sql::odbc::GetSqlWCharSize;
@@ -118,10 +135,26 @@ inline std::string SqlStringToString(const unsigned char* sql_str,
118135
return res;
119136
}
120137

138+
// On Linux, unixodbc defines SQLWCHAR as `unsigned short`
121139
inline std::vector<SQLWCHAR> ToSqlWCharVector(const std::wstring& ws) {
122140
std::vector<SQLWCHAR> buf;
123141
// buf.assign(ws.begin(), ws.end());
124-
// TODO implement in separate PR
142+
// -AL- TODO implement
143+
ARROW_LOG(DEBUG) << "-AL- sizeof(SQLWCHAR):" << sizeof(SQLWCHAR)
144+
<< ", sizeof(wchar_t):" << sizeof(wchar_t);
145+
146+
ARROW_LOG(DEBUG) << "-AL- sizeof(char16_t):" << sizeof(char16_t)
147+
<< ", sizeof(char32_t):" << sizeof(char32_t);
148+
if (sizeof(SQLWCHAR) == sizeof(wchar_t)) {
149+
ARROW_LOG(DEBUG) << "-AL- sizeof(SQLWCHAR) equals sizeof(wchar_t) ";
150+
buf.assign(ws.begin(), ws.end());
151+
// or return std::vector<SQLWCHAR>(ws.begin(), ws.end());
152+
} else {
153+
ARROW_LOG(DEBUG) << "-AL- sizeof(SQLWCHAR) != doesn't equal sizeof(wchar_t) ";
154+
// std::u16string u16s = from wide string to utf16;
155+
// return std::vector<SQLWCHAR>(u16s.begin(), u16s.end());
156+
}
157+
125158
return buf;
126159
}
127160

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@
2525

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

28-
#ifdef __linux__
29-
# define GET_SQWCHAR_PTR(wstring_var) (ODBC::ToSqlWCharVector(wstring_var).data())
30-
#else
31-
// Windows and macOS
32-
# define GET_SQWCHAR_PTR(wstring_var) (wstring_var.c_str())
33-
#endif
34-
3528
namespace arrow::flight::sql::odbc {
3629

3730
using config::Configuration;

0 commit comments

Comments
 (0)