justing-bq commented on code in PR #50562: URL: https://github.com/apache/arrow/pull/50562#discussion_r3639891933
########## cpp/src/arrow/flight/sql/odbc/tests/describe_col_test.cc: ########## @@ -0,0 +1,125 @@ +// 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/tests/odbc_test_suite.h" + +#include "arrow/flight/sql/odbc/odbc_impl/platform.h" + +#include <sql.h> +#include <sqltypes.h> +#include <sqlucode.h> + +#include <gtest/gtest.h> + +namespace arrow::flight::sql::odbc { + +// These tests run against the remote server only. The mock SQLite server +// reports SQL_WVARCHAR metadata for `SELECT ... AS` result columns (see +// ColumnsMockTest in columns_test.cc), so it cannot exercise the numeric or +// datetime branches of SQLDescribeCol that this fix touches. +class DescribeColRemoteTest : public FlightSQLODBCRemoteTestBase {}; + +namespace { +// Sentinel used to pre-fill the SQLULEN column_size output. If SQLDescribeCol +// only writes the low bytes (the width bug this test guards against), the upper +// bytes remain set to this pattern and the value is far outside any legal +// column size. +constexpr SQLULEN kColumnSizeSentinel = static_cast<SQLULEN>(0xFFFFFFFFFFFFFFFFULL); + +// Column ordinals in the all-data-types query (see +// ODBCTestBase::GetQueryAllDataTypes). Decimal and timestamp exercise the +// numeric-precision and datetime-precision code paths in SQLDescribeCol. +constexpr SQLUSMALLINT kDecimalColumn = 17; +constexpr SQLUSMALLINT kTimestampColumn = 31; +} // namespace + +// Verify that SQLDescribeCol fully initializes the SQLULEN column_size output +// for a DECIMAL column. Prior to GH-50560 the numeric path read +// SQL_DESC_PRECISION (a SQLSMALLINT) straight into the SQLULEN* output, writing +// only 2 of the 8 bytes and leaving the upper 6 bytes as uninitialized garbage. +TEST_F(DescribeColRemoteTest, TestSQLDescribeColDecimalColumnSizeIsFullyWritten) { Review Comment: I think it would be better for these tests to be defined in `columns_test.cc` where there are many other `SQLDescribeCol` tests. -- 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]
