Skip to content

Commit af184f5

Browse files
authored
GH-49561: [C++][FlightRPC][ODBC] Use SQLWCHAR array for wide string literals in test suite (#49562)
### Rationale for this change We want to use a SQLWCHAR array for wide string literal inside our test suite instead of a SQLWCHAR vector. ### What changes are included in this PR? SQLWCHAR vector used for wide string literals are replaced with a SQLWCHAR array instead. Columns tests were refactored to perform assertions over std::string equality rather than wide string equality. ### Are these changes tested? Yes ### Are there any user-facing changes? No * GitHub Issue: #49561 Authored-by: justing-bq <62349012+justing-bq@users.noreply.github.com> Signed-off-by: David Li <li.davidm96@gmail.com>
1 parent 999a662 commit af184f5

5 files changed

Lines changed: 647 additions & 671 deletions

File tree

cpp/src/arrow/flight/sql/odbc/odbc_impl/encoding_utils.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
3232

3333
namespace ODBC {
34+
using arrow::flight::sql::odbc::WcsToUtf8;
3435

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

103+
/// \brief Convert vector of SqlWchar to standard string
104+
/// \param[in] wchar_vec SqlWchar vector to convert
105+
/// \return wchar_vec in std::string format
106+
inline std::string SqlWcharToString(const std::vector<SQLWCHAR>& wchar_vec) {
107+
if (wchar_vec.empty() || wchar_vec[0] == 0) {
108+
return {};
109+
}
110+
111+
auto end = std::find(wchar_vec.begin(), wchar_vec.end(), 0);
112+
size_t actual_len = std::distance(wchar_vec.begin(), end);
113+
114+
thread_local std::vector<uint8_t> utf8_str;
115+
116+
WcsToUtf8((void*)wchar_vec.data(), static_cast<SQLINTEGER>(actual_len), &utf8_str);
117+
118+
return std::string(utf8_str.begin(), utf8_str.end());
119+
}
120+
102121
inline std::string SqlStringToString(const unsigned char* sql_str,
103122
int32_t sql_str_len = SQL_NTS) {
104123
std::string res;

0 commit comments

Comments
 (0)