-
Notifications
You must be signed in to change notification settings - Fork 4.3k
GH-50852: [C++][FlightRPC][ODBC] Decode wide connection/descriptor string attributes with the wide decoder #50853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we consolidate into an existing file?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tricky part is SQL_DESC_NAME can't be exercised through a public entry point. I had tried a black-box test via SQLGetStmtAttr(SQL_ATTR_APP_ROW_DESC) + SQLSetDescField(ard, 1, SQL_DESC_NAME, …), but that path returns SQL_ERROR (the field isn't settable on the ARD through the DM), so the only way to reach ODBCDescriptor::SetField(SQL_DESC_NAME) is a direct unit test on ODBCDescriptor. There's no existing descriptor unit test in odbc_impl/ to merge into, and the unit tests there follow a 1:1 source↔test naming convention (util.cc↔util_test.cc, json_converter.cc↔json_converter_test.cc, etc.), so odbc_descriptor_test.cc fit that pattern. Happy to fold it elsewhere if you'd prefer though, e.g. into util_test.cc. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #include "arrow/flight/sql/odbc/odbc_impl/odbc_descriptor.h" | ||
|
|
||
| #include "arrow/flight/sql/odbc/odbc_impl/diagnostics.h" | ||
| #include "arrow/flight/sql/odbc/odbc_impl/encoding.h" | ||
| #include "arrow/flight/sql/odbc/odbc_impl/encoding_utils.h" | ||
|
|
||
| #include <sql.h> | ||
| #include <sqlext.h> | ||
|
|
||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace arrow::flight::sql::odbc { | ||
|
|
||
| using ODBC::ODBCDescriptor; | ||
|
|
||
| TEST(ODBCDescriptorTest, SetGetNameWideRoundTrips) { | ||
| arrow::flight::sql::odbc::Diagnostics diagnostics("vendor", "component", | ||
| OdbcVersion::V_3); | ||
| ODBCDescriptor desc(diagnostics, nullptr, nullptr, /*is_app_descriptor=*/true, | ||
| /*is_writable=*/true, /*is_2x_connection=*/false); | ||
|
|
||
| SQLSMALLINT count = 1; | ||
| desc.SetHeaderField(SQL_DESC_COUNT, reinterpret_cast<SQLPOINTER>(&count), 0); | ||
|
|
||
| std::vector<uint8_t> wide; | ||
| Utf8ToWcs("my_column", &wide); | ||
| desc.SetField(1, SQL_DESC_NAME, wide.data(), static_cast<SQLINTEGER>(wide.size())); | ||
|
|
||
| SQLWCHAR out[256]; | ||
| SQLINTEGER out_len = 0; | ||
| desc.GetField(1, SQL_DESC_NAME, out, sizeof(out), &out_len); | ||
| std::string name = | ||
| ODBC::SqlWcharToString(out, static_cast<SQLSMALLINT>(out_len / GetSqlWCharSize())); | ||
| EXPECT_EQ("my_column", name); | ||
| } | ||
|
|
||
| } // namespace arrow::flight::sql::odbc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch — added
ODBCDescriptorTest.SetGetNameWideRoundTripsinodbc_descriptor_test.cc, a directSetField/GetFieldround-trip onSQL_DESC_NAMEwith a multi-character wide name. It passes with the fix and fails without it (the byte-wise decode corrupts the stored UTF-16, which the wide getter then rejects). A black-box test isn't possible here since there's noSQLSetDescFieldentry point wired up, so the unit test onODBCDescriptorcovers it directly.