-
Notifications
You must be signed in to change notification settings - Fork 3.9k
GH-47726 : [C++][FlightRPC] ODBC Unicode Support #47771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
0a88aeb
4c2306a
e8a262c
89d72ee
004b470
1f241a2
08bf224
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |
|
|
||
| #include "arrow/flight/sql/odbc/odbc_impl/config/configuration.h" | ||
| #include "arrow/flight/sql/odbc/odbc_impl/flight_sql_connection.h" | ||
| #include "arrow/result.h" | ||
| #include "arrow/util/utf8.h" | ||
|
|
||
| #include <odbcinst.h> | ||
| #include <boost/range/adaptor/map.hpp> | ||
|
|
@@ -26,7 +28,6 @@ | |
|
|
||
| namespace arrow::flight::sql::odbc { | ||
| namespace config { | ||
|
|
||
| static const char DEFAULT_DSN[] = "Apache Arrow Flight SQL"; | ||
| static const char DEFAULT_ENABLE_ENCRYPTION[] = TRUE_STR; | ||
| static const char DEFAULT_USE_CERT_STORE[] = TRUE_STR; | ||
|
|
@@ -35,23 +36,27 @@ static const char DEFAULT_DISABLE_CERT_VERIFICATION[] = FALSE_STR; | |
| namespace { | ||
| std::string ReadDsnString(const std::string& dsn, const std::string_view& key, | ||
| const std::string& dflt = "") { | ||
| #define BUFFER_SIZE (1024) | ||
| std::vector<char> buf(BUFFER_SIZE); | ||
| std::wstring wdsn = arrow::util::UTF8ToWideString(dsn).ValueOr(L""); | ||
|
||
| std::wstring wkey = arrow::util::UTF8ToWideString(key).ValueOr(L""); | ||
| std::wstring wdflt = arrow::util::UTF8ToWideString(dflt).ValueOr(L""); | ||
|
|
||
| std::string key_str = std::string(key); | ||
| #define BUFFER_SIZE (1024) | ||
| std::vector<wchar_t> buf(BUFFER_SIZE); | ||
| int ret = | ||
| SQLGetPrivateProfileString(dsn.c_str(), key_str.c_str(), dflt.c_str(), buf.data(), | ||
| static_cast<int>(buf.size()), "ODBC.INI"); | ||
| SQLGetPrivateProfileString(wdsn.c_str(), wkey.c_str(), wdflt.c_str(), buf.data(), | ||
| static_cast<int>(buf.size()), L"ODBC.INI"); | ||
|
|
||
| if (ret > BUFFER_SIZE) { | ||
| // If there wasn't enough space, try again with the right size buffer. | ||
| buf.resize(ret + 1); | ||
| ret = | ||
| SQLGetPrivateProfileString(dsn.c_str(), key_str.c_str(), dflt.c_str(), buf.data(), | ||
| static_cast<int>(buf.size()), "ODBC.INI"); | ||
| SQLGetPrivateProfileString(wdsn.c_str(), wkey.c_str(), wdflt.c_str(), buf.data(), | ||
| static_cast<int>(buf.size()), L"ODBC.INI"); | ||
| } | ||
|
|
||
| return std::string(buf.data(), ret); | ||
| std::wstring wresult = std::wstring(buf.data(), ret); | ||
| std::string result = arrow::util::WideStringToUTF8(wresult).ValueOr(""); | ||
|
||
| return result; | ||
| } | ||
|
|
||
| void RemoveAllKnownKeys(std::vector<std::string>& keys) { | ||
|
|
@@ -68,28 +73,32 @@ void RemoveAllKnownKeys(std::vector<std::string>& keys) { | |
| } | ||
|
|
||
| std::vector<std::string> ReadAllKeys(const std::string& dsn) { | ||
lidavidm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| std::vector<char> buf(BUFFER_SIZE); | ||
| std::wstring wDsn = arrow::util::UTF8ToWideString(dsn).ValueOr(L""); | ||
|
|
||
| std::vector<wchar_t> buf(BUFFER_SIZE); | ||
|
|
||
| int ret = SQLGetPrivateProfileString(dsn.c_str(), NULL, "", buf.data(), | ||
| static_cast<int>(buf.size()), "ODBC.INI"); | ||
| int ret = SQLGetPrivateProfileString(wDsn.c_str(), NULL, L"", buf.data(), | ||
| static_cast<int>(buf.size()), L"ODBC.INI"); | ||
|
|
||
| if (ret > BUFFER_SIZE) { | ||
| // If there wasn't enough space, try again with the right size buffer. | ||
| buf.resize(ret + 1); | ||
| ret = SQLGetPrivateProfileString(dsn.c_str(), NULL, "", buf.data(), | ||
| static_cast<int>(buf.size()), "ODBC.INI"); | ||
| ret = SQLGetPrivateProfileString(wDsn.c_str(), NULL, L"", buf.data(), | ||
| static_cast<int>(buf.size()), L"ODBC.INI"); | ||
| } | ||
|
|
||
| // When you pass NULL to SQLGetPrivateProfileString it gives back a \0 delimited list of | ||
| // all the keys. The below loop simply tokenizes all the keys and places them into a | ||
| // vector. | ||
| std::vector<std::string> keys; | ||
| char* begin = buf.data(); | ||
| wchar_t* begin = buf.data(); | ||
| while (begin && *begin != '\0') { | ||
| char* cur; | ||
| wchar_t* cur; | ||
| for (cur = begin; *cur != '\0'; ++cur) { | ||
| } | ||
| keys.emplace_back(begin, cur); | ||
|
|
||
| std::string key = arrow::util::WideStringToUTF8(std::wstring(begin, cur)).ValueOr(""); | ||
| keys.emplace_back(key); | ||
| begin = ++cur; | ||
| } | ||
| return keys; | ||
|
|
@@ -153,6 +162,11 @@ const std::string& Configuration::Get(const std::string_view& key) const { | |
| return itr->second; | ||
| } | ||
|
|
||
| void Configuration::Set(const std::string_view& key, const std::wstring& wValue) { | ||
| std::string value = arrow::util::WideStringToUTF8(wValue).ValueOr(""); | ||
| Set(key, value); | ||
| } | ||
|
|
||
| void Configuration::Set(const std::string_view& key, const std::string& value) { | ||
| const std::string copy = boost::trim_copy(value); | ||
| if (!copy.empty()) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.