-
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0a88aeb
Unicode support for DSN ODBC APIs
alinaliBQ 4c2306a
Fix for `GetAttributeSQLWCHAR` for truncation error
alinaliBQ e8a262c
Fix lint
alinaliBQ 89d72ee
Fix variable names
alinaliBQ 004b470
Address David's comments
alinaliBQ 1f241a2
Address David's comments
alinaliBQ 08bf224
add throws
alinaliBQ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { | ||
lidavidm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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()) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we ignoring errors here?
I suppose the return type doesn't allow for errors. But I'd expect that we update the return type to
Result<std::string>.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You raise a good point, these errors should not be ignored. I have added throws for the Result errors.
The caller will catch the exceptions thrown