lidavidm commented on code in PR #47772:
URL: https://github.com/apache/arrow/pull/47772#discussion_r2454494162


##########
cpp/src/arrow/flight/sql/odbc/tests/connection_attr_test.cc:
##########
@@ -0,0 +1,362 @@
+// 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 {
+
+template <typename T>
+class ConnectionAttributeTest : public T {};
+
+using TestTypes =
+    ::testing::Types<FlightSQLODBCMockTestBase, FlightSQLODBCRemoteTestBase>;
+TYPED_TEST_SUITE(ConnectionAttributeTest, TestTypes);
+
+#ifdef SQL_ATTR_ASYNC_DBC_EVENT
+TYPED_TEST(ConnectionAttributeTest, 
TestSQLSetConnectAttrAsyncDbcEventUnsupported) {
+  ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(this->conn, SQL_ATTR_ASYNC_DBC_EVENT, 
0, 0));
+  // Driver Manager on Windows returns error code HY118
+  VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHY118);
+}
+#endif
+
+#ifdef SQL_ATTR_ASYNC_ENABLE
+TYPED_TEST(ConnectionAttributeTest, 
TestSQLSetConnectAttrAyncEnableUnsupported) {
+  ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(this->conn, SQL_ATTR_ASYNC_ENABLE, 0, 
0));
+  VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHYC00);
+}
+#endif
+
+#ifdef SQL_ATTR_ASYNC_DBC_PCALLBACK
+TYPED_TEST(ConnectionAttributeTest, 
TestSQLSetConnectAttrAyncDbcPcCallbackUnsupported) {
+  ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(this->conn, 
SQL_ATTR_ASYNC_DBC_PCALLBACK, 0, 0));
+  VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHYC00);
+}
+#endif
+
+#ifdef SQL_ATTR_ASYNC_DBC_PCONTEXT
+TYPED_TEST(ConnectionAttributeTest, 
TestSQLSetConnectAttrAyncDbcPcContextUnsupported) {
+  ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(this->conn, 
SQL_ATTR_ASYNC_DBC_PCONTEXT, 0, 0));
+  VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHYC00);
+}
+#endif
+
+TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrAutoIpdReadOnly) {
+  // Verify read-only attribute cannot be set
+  ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(this->conn, SQL_ATTR_AUTO_IPD, 0, 0));
+  VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHY092);
+}
+
+TYPED_TEST(ConnectionAttributeTest, 
TestSQLSetConnectAttrConnectionDeadReadOnly) {
+  // Verify read-only attribute cannot be set
+  ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(this->conn, SQL_ATTR_CONNECTION_DEAD, 
0, 0));
+  VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHY092);
+}
+
+#ifdef SQL_ATTR_DBC_INFO_TOKEN
+TYPED_TEST(ConnectionAttributeTest, 
TestSQLSetConnectAttrDbcInfoTokenUnsupported) {
+  ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(this->conn, SQL_ATTR_DBC_INFO_TOKEN, 
0, 0));
+  VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHYC00);
+}
+#endif
+
+TYPED_TEST(ConnectionAttributeTest, 
TestSQLSetConnectAttrEnlistInDtcUnsupported) {
+  ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(this->conn, SQL_ATTR_ENLIST_IN_DTC, 
0, 0));
+  VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHYC00);
+}
+
+TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrOdbcCursorsDMOnly) {
+  this->AllocEnvConnHandles();
+
+  // Verify DM-only attribute is settable via Driver Manager
+  ASSERT_EQ(SQL_SUCCESS,
+            SQLSetConnectAttr(this->conn, SQL_ATTR_ODBC_CURSORS,
+                              
reinterpret_cast<SQLPOINTER>(SQL_CUR_USE_DRIVER), 0));
+
+  std::string connect_str = this->GetConnectionString();
+  this->ConnectWithString(connect_str);
+}
+
+TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrQuietModeReadOnly) {
+  // Verify read-only attribute cannot be set
+  ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(this->conn, SQL_ATTR_QUIET_MODE, 0, 
0));
+  VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHY092);
+}
+
+TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrTraceDMOnly) {
+  // Verify DM-only attribute is settable via Driver Manager
+  ASSERT_EQ(SQL_SUCCESS,
+            SQLSetConnectAttr(this->conn, SQL_ATTR_TRACE,
+                              reinterpret_cast<SQLPOINTER>(SQL_OPT_TRACE_OFF), 
0));
+}
+
+TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrTracefileDMOnly) {
+  // Verify DM-only attribute is handled by Driver Manager
+
+  // Use placeholder value as we want the call to fail, or else
+  // the driver manager will produce a trace file.
+  std::wstring trace_file = L"invalid/file/path";
+  std::vector<SQLWCHAR> trace_file0(trace_file.begin(), trace_file.end());
+  ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(this->conn, SQL_ATTR_TRACEFILE, 
&trace_file0[0],
+                                         
static_cast<SQLINTEGER>(trace_file0.size())));
+  VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHY000);
+}
+
+TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrTranslateLabDMOnly) {
+  // Verify DM-only attribute is handled by Driver Manager
+  ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(this->conn, SQL_ATTR_TRANSLATE_LIB, 
0, 0));
+  // Checks for invalid argument return error
+  VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHY024);
+}
+
+TYPED_TEST(ConnectionAttributeTest, 
TestSQLSetConnectAttrTranslateOptionUnsupported) {
+  ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(this->conn, 
SQL_ATTR_TRANSLATE_OPTION, 0, 0));
+  VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHYC00);
+}
+
+TYPED_TEST(ConnectionAttributeTest, 
TestSQLSetConnectAttrTxnIsolationUnsupported) {
+  ASSERT_EQ(SQL_ERROR,
+            SQLSetConnectAttr(this->conn, SQL_ATTR_TXN_ISOLATION,
+                              
reinterpret_cast<SQLPOINTER>(SQL_TXN_READ_UNCOMMITTED), 0));
+  VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHYC00);
+}
+
+#ifdef SQL_ATTR_DBC_INFO_TOKEN
+TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrDbcInfoTokenSetOnly) {
+  // Verify that set-only attribute cannot be read
+  SQLPOINTER ptr = NULL;
+  ASSERT_EQ(SQL_ERROR, SQLGetConnectAttr(this->conn, SQL_ATTR_DBC_INFO_TOKEN, 
ptr, 0, 0));
+  VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHY092);
+}
+#endif
+
+TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrOdbcCursorsDMOnly) {
+  // Verify that DM-only attribute is handled by driver manager
+  SQLULEN cursor_attr;
+  ASSERT_EQ(SQL_SUCCESS,
+            SQLGetConnectAttr(this->conn, SQL_ATTR_ODBC_CURSORS, &cursor_attr, 
0, 0));
+  EXPECT_EQ(SQL_CUR_USE_DRIVER, cursor_attr);
+}
+
+TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTraceDMOnly) {
+  // Verify that DM-only attribute is handled by driver manager
+  SQLUINTEGER trace;
+  ASSERT_EQ(SQL_SUCCESS, SQLGetConnectAttr(this->conn, SQL_ATTR_TRACE, &trace, 
0, 0));
+  EXPECT_EQ(SQL_OPT_TRACE_OFF, trace);
+}
+
+TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTraceFileDMOnly) {
+  // Verify that DM-only attribute is handled by driver manager
+  SQLWCHAR out_str[kOdbcBufferSize];
+  SQLINTEGER out_str_len;
+  ASSERT_EQ(SQL_SUCCESS, SQLGetConnectAttr(this->conn, SQL_ATTR_TRACEFILE, 
out_str,
+                                           kOdbcBufferSize, &out_str_len));
+  // Length is returned in bytes for SQLGetConnectAttr,
+  // we want the number of characters
+  out_str_len /= arrow::flight::sql::odbc::GetSqlWCharSize();
+  std::string out_connection_string =
+      ODBC::SqlWcharToString(out_str, static_cast<SQLSMALLINT>(out_str_len));
+  EXPECT_TRUE(!out_connection_string.empty());

Review Comment:
   nit: EXPECT_FALSE



-- 
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]

Reply via email to