From a355afd066c48eada014ccad1ec7b165399f396b Mon Sep 17 00:00:00 2001 From: vanshaj2023 Date: Sat, 23 May 2026 00:30:38 +0530 Subject: [PATCH] GH-49482: fix inconsistent SQLGetInfo values in global connection --- .../sql/odbc/odbc_impl/get_info_cache.cc | 41 ++++++++++--------- .../sql/odbc/tests/connection_info_test.cc | 27 ++---------- 2 files changed, 24 insertions(+), 44 deletions(-) diff --git a/cpp/src/arrow/flight/sql/odbc/odbc_impl/get_info_cache.cc b/cpp/src/arrow/flight/sql/odbc/odbc_impl/get_info_cache.cc index 6923d7fafbe4..5654a4e5aa01 100644 --- a/cpp/src/arrow/flight/sql/odbc/odbc_impl/get_info_cache.cc +++ b/cpp/src/arrow/flight/sql/odbc/odbc_impl/get_info_cache.cc @@ -395,25 +395,21 @@ bool GetInfoCache::LoadInfoFromServer() { // Unused by ODBC. break; case SqlInfoOptions::SQL_DDL_SCHEMA: { - // GH-49500 TODO: use scalar bool to determine `SQL_CREATE_SCHEMA` and - // `SQL_DROP_SCHEMA` values - - // Note: this is a bitmask and we can't describe cascade or restrict - // flags. - info_[SQL_DROP_SCHEMA] = static_cast(SQL_DS_DROP_SCHEMA); - - // Note: this is a bitmask and we can't describe authorization or - // collation - info_[SQL_CREATE_SCHEMA] = static_cast(SQL_CS_CREATE_SCHEMA); + bool supported = + reinterpret_cast(scalar->child_value().get())->value; + info_[SQL_DROP_SCHEMA] = + static_cast(supported ? SQL_DS_DROP_SCHEMA : 0); + info_[SQL_CREATE_SCHEMA] = + static_cast(supported ? SQL_CS_CREATE_SCHEMA : 0); break; } case SqlInfoOptions::SQL_DDL_TABLE: { - // GH-49500 TODO: use scalar bool to determine `SQL_CREATE_TABLE` and - // `SQL_DROP_TABLE` values - - // This is a bitmask and we cannot describe all clauses. - info_[SQL_CREATE_TABLE] = static_cast(SQL_CT_CREATE_TABLE); - info_[SQL_DROP_TABLE] = static_cast(SQL_DT_DROP_TABLE); + bool supported = + reinterpret_cast(scalar->child_value().get())->value; + info_[SQL_CREATE_TABLE] = + static_cast(supported ? SQL_CT_CREATE_TABLE : 0); + info_[SQL_DROP_TABLE] = + static_cast(supported ? SQL_DT_DROP_TABLE : 0); break; } case SqlInfoOptions::SQL_ALL_TABLES_ARE_SELECTABLE: { @@ -475,10 +471,15 @@ bool GetInfoCache::LoadInfoFromServer() { break; } case SqlInfoOptions::SQL_CATALOG_AT_START: { - info_[SQL_CATALOG_LOCATION] = static_cast( - reinterpret_cast(scalar->child_value().get())->value - ? SQL_CL_START - : SQL_CL_END); + // Only use this as a fallback if ARROW_SQL_CATALOG_TERM has not already + // set SQL_CATALOG_LOCATION (to avoid conflicting writes depending on + // response key ordering). + SetDefaultIfMissing( + info_, SQL_CATALOG_LOCATION, + static_cast( + reinterpret_cast(scalar->child_value().get())->value + ? SQL_CL_START + : SQL_CL_END)); break; } case SqlInfoOptions::SQL_SELECT_FOR_UPDATE_SUPPORTED: diff --git a/cpp/src/arrow/flight/sql/odbc/tests/connection_info_test.cc b/cpp/src/arrow/flight/sql/odbc/tests/connection_info_test.cc index 257e8affa48e..6aa7a4e81bb8 100644 --- a/cpp/src/arrow/flight/sql/odbc/tests/connection_info_test.cc +++ b/cpp/src/arrow/flight/sql/odbc/tests/connection_info_test.cc @@ -616,18 +616,11 @@ TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoAlterTable) { EXPECT_EQ(static_cast(0), value); } -TYPED_TEST(ConnectionInfoHandleTest, TestSQLGetInfoCatalogLocation) { - // GH-49482 TODO: resolve inconsitent return value for SQL_CATALOG_LOCATION and change - // test type to `ConnectionInfoTest` - this->ConnectWithString(this->GetConnectionString(), this->conn); - +TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoCatalogLocation) { SQLUSMALLINT value; GetInfo(this->conn, SQL_CATALOG_LOCATION, &value); EXPECT_EQ(static_cast(0), value); - - EXPECT_EQ(SQL_SUCCESS, SQLDisconnect(this->conn)) - << GetOdbcErrorMessage(SQL_HANDLE_DBC, this->conn); } TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoCatalogName) { @@ -752,32 +745,18 @@ TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoDropDomain) { EXPECT_EQ(static_cast(0), value); } -TYPED_TEST(ConnectionInfoHandleTest, TestSQLGetInfoDropSchema) { - // GH-49482 TODO: resolve inconsitent return value for SQL_DROP_SCHEMA and change test - // type to `ConnectionInfoTest` - this->ConnectWithString(this->GetConnectionString(), this->conn); - +TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoDropSchema) { SQLUINTEGER value; GetInfo(this->conn, SQL_DROP_SCHEMA, &value); EXPECT_EQ(static_cast(0), value); - - EXPECT_EQ(SQL_SUCCESS, SQLDisconnect(this->conn)) - << GetOdbcErrorMessage(SQL_HANDLE_DBC, this->conn); } -TYPED_TEST(ConnectionInfoHandleTest, TestSQLGetInfoDropTable) { - // GH-49482 TODO: resolve inconsitent return value for SQL_DROP_TABLE and change test - // type to `ConnectionInfoTest` - this->ConnectWithString(this->GetConnectionString(), this->conn); - +TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoDropTable) { SQLUINTEGER value; GetInfo(this->conn, SQL_DROP_TABLE, &value); EXPECT_EQ(static_cast(0), value); - - EXPECT_EQ(SQL_SUCCESS, SQLDisconnect(this->conn)) - << GetOdbcErrorMessage(SQL_HANDLE_DBC, this->conn); } TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoDropTranslation) {