MCPcopy Create free account
hub / github.com/apache/arrow / ConvertToSQLWCHAR

Function ConvertToSQLWCHAR

cpp/src/arrow/flight/sql/odbc/odbc_impl/system_dsn.cc:34–145  ·  view source on GitHub ↗

Linux driver manager uses utf16string

Source from the content-addressed store, hash-verified

32#ifdef __linux__
33// Linux driver manager uses utf16string
34std::u16string ConvertToSQLWCHAR(const std::string_view var) {
35 auto result = arrow::util::UTF8StringToUTF16(var);
36#else
37std::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
48void PostError(DWORD error_code, LPWSTR error_msg) {
49#if defined _WIN32
50 MessageBox(NULL, error_msg, L"Error!", MB_ICONEXCLAMATION | MB_OK);
51#endif // _WIN32
52 SQLPostInstallerError(error_code, error_msg);
53}
54
55void PostArrowUtilError(arrow::Status error_status) {
56 std::string error_msg = error_status.message();
57 CONVERT_SQLWCHAR_STR(werror_msg, error_msg);
58
59 PostError(ODBC_ERROR_GENERAL_ERR,
60 const_cast<LPWSTR>(reinterpret_cast<LPCWSTR>(werror_msg.c_str())));
61}
62
63void PostLastInstallerError() {
64#define BUFFER_SIZE (1024)
65 DWORD code;
66 std::vector<SQLWCHAR> msg(BUFFER_SIZE);
67 SQLInstallerError(1, &code, msg.data(), BUFFER_SIZE, NULL);
68
69#ifdef __linux__
70 std::string code_str = std::to_string(code);
71 std::u16string code_u16 = arrow::util::UTF8StringToUTF16(code_str).ValueOr(
72 u"unknown code. Error during utf8 to utf16 conversion");
73 std::u16string error_msg = u"Message: \"" +
74 std::u16string(reinterpret_cast<char16_t*>(msg.data())) +
75 u"\", Code: " + code_u16;
76#else
77 // Windows/macOS
78 std::wstring error_msg =
79 L"Message: \"" + std::wstring(msg.data()) + L"\", Code: " + std::to_wstring(code);
80#endif // __linux__
81
82 PostError(code, const_cast<LPWSTR>(reinterpret_cast<LPCWSTR>(error_msg.c_str())));
83}
84
85/**
86 * Unregister specified DSN.
87 *
88 * @param dsn DSN name.
89 * @return True on success and false on fail.
90 */
91bool UnregisterDsn(const std::wstring& dsn) {

Callers 1

RegisterDsnFunction · 0.85

Calls 6

UTF8StringToUTF16Function · 0.85
UTF8ToWideStringFunction · 0.85
PostArrowUtilErrorFunction · 0.85
ValueOrDieMethod · 0.80
okMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected