justing-bq commented on code in PR #49668:
URL: https://github.com/apache/arrow/pull/49668#discussion_r3127380022
##########
cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.cc:
##########
@@ -510,13 +510,45 @@ std::wstring GetStringColumnW(SQLHSTMT stmt, int col_id) {
return std::wstring(buf, buf + char_count);
}
-std::wstring ConvertToWString(const std::vector<SQLWCHAR>& str_val,
SQLSMALLINT str_len) {
+size_t SqlWCharArrLen(const SQLWCHAR* str_val) {
+ if (!str_val) {
+ return 0;
+ }
+ const SQLWCHAR* p = str_val;
+ while (*p != 0) {
+ ++p;
+ }
+ return static_cast<size_t>(p - str_val);
+}
+
+std::wstring ConvertToWString(const SQLWCHAR* str_val, SQLSMALLINT str_len,
+ SQLSMALLINT buffer_size) {
+ if (str_len == -1) {
+#ifdef __linux__
+ str_len = SqlWCharArrLen(str_val);
+#else // Windows & Mac
+ str_len = std::wcslen(str_val);
+#endif
+ }
+ std::wstring attr_str;
+ if (str_len == 0) {
+ attr_str = L"";
+ } else {
+ assert(str_val != nullptr);
+ assert(str_len > 0 && str_len <= buffer_size);
+ attr_str.assign(str_val, str_val + str_len);
+ }
+ return attr_str;
+}
+
+std::wstring ConvertToWString(const std::vector<SQLWCHAR>& str_val,
SQLSMALLINT str_len,
+ SQLSMALLINT buffer_size) {
std::wstring attr_str;
if (str_len == 0) {
- attr_str = std::wstring(&str_val[0]);
+ attr_str = L"";
} else {
EXPECT_GT(str_len, 0);
- EXPECT_LE(str_len, static_cast<SQLSMALLINT>(kOdbcBufferSize));
+ EXPECT_LE(str_len, buffer_size);
Review Comment:
buffer_size is correctly figured out from the calling code before passing it
in here. Doing this comment's suggestion just complicates things unnecessarily.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]