|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +#include "arrow/flight/sql/odbc/odbc_impl/odbc_descriptor.h" |
| 19 | + |
| 20 | +#include "arrow/flight/sql/odbc/odbc_impl/diagnostics.h" |
| 21 | +#include "arrow/flight/sql/odbc/odbc_impl/encoding.h" |
| 22 | +#include "arrow/flight/sql/odbc/odbc_impl/encoding_utils.h" |
| 23 | + |
| 24 | +#include <sql.h> |
| 25 | +#include <sqlext.h> |
| 26 | + |
| 27 | +#include "gtest/gtest.h" |
| 28 | + |
| 29 | +namespace arrow::flight::sql::odbc { |
| 30 | + |
| 31 | +using ODBC::ODBCDescriptor; |
| 32 | + |
| 33 | +TEST(ODBCDescriptorTest, SetGetNameWideRoundTrips) { |
| 34 | + arrow::flight::sql::odbc::Diagnostics diagnostics("vendor", "component", |
| 35 | + OdbcVersion::V_3); |
| 36 | + ODBCDescriptor desc(diagnostics, nullptr, nullptr, /*is_app_descriptor=*/true, |
| 37 | + /*is_writable=*/true, /*is_2x_connection=*/false); |
| 38 | + |
| 39 | + SQLSMALLINT count = 1; |
| 40 | + desc.SetHeaderField(SQL_DESC_COUNT, reinterpret_cast<SQLPOINTER>(&count), 0); |
| 41 | + |
| 42 | + std::vector<uint8_t> wide; |
| 43 | + Utf8ToWcs("my_column", &wide); |
| 44 | + desc.SetField(1, SQL_DESC_NAME, wide.data(), static_cast<SQLINTEGER>(wide.size())); |
| 45 | + |
| 46 | + SQLWCHAR out[256]; |
| 47 | + SQLINTEGER out_len = 0; |
| 48 | + desc.GetField(1, SQL_DESC_NAME, out, sizeof(out), &out_len); |
| 49 | + std::string name = |
| 50 | + ODBC::SqlWcharToString(out, static_cast<SQLSMALLINT>(out_len / GetSqlWCharSize())); |
| 51 | + EXPECT_EQ("my_column", name); |
| 52 | +} |
| 53 | + |
| 54 | +} // namespace arrow::flight::sql::odbc |
0 commit comments