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-
4928namespace arrow ::flight::sql::odbc {
5029
5130using 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+
5348void 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 */
119114bool 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