Skip to content

Commit 2cde7e7

Browse files
authored
Use SqlWCharArrLen() for wide char array length on Linux
1 parent 851063e commit 2cde7e7

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,20 @@ std::wstring GetStringColumnW(SQLHSTMT stmt, int col_id) {
510510
return std::wstring(buf, buf + char_count);
511511
}
512512

513+
size_t SqlWCharArrLen(const SQLWCHAR* str_val) {
514+
if (!str_val) {
515+
return 0;
516+
}
517+
const SQLWCHAR* p = str_val;
518+
while (*p != 0) {
519+
++p;
520+
}
521+
return static_cast<size_t>(p - str_val);
522+
}
523+
513524
std::wstring ConvertToWString(const SQLWCHAR* str_val) {
514525
#ifdef __linux__
515-
size_t str_len = std::wcslen(reinterpret_cast<const wchar_t*>(str_val));
526+
size_t str_len = SqlWCharArrLen(str_val);
516527
#else
517528
size_t str_len = std::wcslen(str_val);
518529
#endif

cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
SQLWCHAR* name = name##_vec.data();
4545
# define ASSIGN_SQLWCHAR_ARR_AND_LEN(name, wstring_var) \
4646
ASSIGN_SQLWCHAR_ARR(name, wstring_var) \
47-
size_t name##_len = std::wcslen(reinterpret_cast<const wchar_t*>(name));
47+
size_t name##_len = SqlWCharArrLen(name);
4848
#else
4949
# define ASSIGN_SQLWCHAR_ARR(name, wstring_var) SQLWCHAR name[] = wstring_var;
5050
# define ASSIGN_SQLWCHAR_ARR_AND_LEN(name, wstring_var) \
@@ -281,6 +281,11 @@ bool WriteDSN(Connection::ConnPropertyMap properties);
281281
/// \return wstring
282282
std::wstring GetStringColumnW(SQLHSTMT stmt, int col_id);
283283

284+
/// \brief Get length of wide char array.
285+
/// \param[in] str_val Array of SQLWCHAR.
286+
/// \return number of wide characters in array
287+
size_t SqlWCharArrLen(const SQLWCHAR* str_val);
288+
284289
/// \brief Check wide char array and convert into wstring
285290
/// \param[in] str_val Array of SQLWCHAR.
286291
/// \return wstring

0 commit comments

Comments
 (0)