Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/odbc_impl/encoding_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING

namespace ODBC {
using arrow::flight::sql::odbc::WcsToUtf8;

// Return the number of bytes required for the conversion.
template <typename CHAR_TYPE>
Expand Down Expand Up @@ -99,6 +100,24 @@ inline std::string SqlWcharToString(SQLWCHAR* wchar_msg, SQLINTEGER msg_len = SQ
return std::string(utf8_str.begin(), utf8_str.end());
}

/// \brief Convert vector of SqlWchar to standard string
/// \param[in] wchar_vec SqlWchar vector to convert
/// \return wchar_vec in std::string format
inline std::string SqlWcharToString(const std::vector<SQLWCHAR>& wchar_vec) {
if (wchar_vec.empty() || wchar_vec[0] == 0) {
return {};
}

auto end = std::find(wchar_vec.begin(), wchar_vec.end(), 0);
size_t actual_len = std::distance(wchar_vec.begin(), end);

thread_local std::vector<uint8_t> utf8_str;

WcsToUtf8((void*)wchar_vec.data(), static_cast<SQLINTEGER>(actual_len), &utf8_str);

return std::string(utf8_str.begin(), utf8_str.end());
}

inline std::string SqlStringToString(const unsigned char* sql_str,
int32_t sql_str_len = SQL_NTS) {
std::string res;
Expand Down
Loading
Loading