alinaliBQ commented on code in PR #47762:
URL: https://github.com/apache/arrow/pull/47762#discussion_r2446338347


##########
cpp/src/arrow/flight/sql/odbc/tests/connection_info_test.cc:
##########
@@ -0,0 +1,1489 @@
+// 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"
+
+#ifdef _WIN32
+#  include <windows.h>
+#endif
+
+#include <sql.h>
+#include <sqltypes.h>
+#include <sqlucode.h>
+
+#include "gtest/gtest.h"
+
+namespace arrow::flight::sql::odbc {
+
+// Helper Functions
+
+// Validate unsigned short SQLUSMALLINT return value
+void Validate(SQLHDBC connection, SQLUSMALLINT info_type, SQLUSMALLINT 
expected_value) {
+  SQLUSMALLINT info_value;
+  SQLSMALLINT message_length;
+
+  SQLRETURN ret = SQLGetInfo(connection, info_type, &info_value, 0, 
&message_length);
+
+  EXPECT_EQ(SQL_SUCCESS, ret);
+
+  EXPECT_EQ(expected_value, info_value);
+}
+
+// Validate unsigned long SQLUINTEGER return value
+void Validate(SQLHDBC connection, SQLUSMALLINT info_type, SQLUINTEGER 
expected_value) {
+  SQLUINTEGER info_value;
+  SQLSMALLINT message_length;
+
+  SQLRETURN ret = SQLGetInfo(connection, info_type, &info_value, 0, 
&message_length);
+
+  EXPECT_EQ(SQL_SUCCESS, ret);
+
+  EXPECT_EQ(expected_value, info_value);
+}
+
+// Validate unsigned length SQLULEN return value
+void Validate(SQLHDBC connection, SQLUSMALLINT info_type, SQLULEN 
expected_value) {
+  SQLULEN info_value;
+  SQLSMALLINT message_length;
+
+  SQLRETURN ret = SQLGetInfo(connection, info_type, &info_value, 0, 
&message_length);
+
+  EXPECT_EQ(SQL_SUCCESS, ret);
+
+  EXPECT_EQ(expected_value, info_value);
+}
+
+// Validate wchar string SQLWCHAR return value
+void Validate(SQLHDBC connection, SQLUSMALLINT info_type, SQLWCHAR* 
expected_value) {
+  SQLWCHAR info_value[ODBC_BUFFER_SIZE] = L"";
+  SQLSMALLINT message_length;
+
+  SQLRETURN ret =
+      SQLGetInfo(connection, info_type, info_value, ODBC_BUFFER_SIZE, 
&message_length);
+
+  EXPECT_EQ(SQL_SUCCESS, ret);
+
+  EXPECT_EQ(*expected_value, *info_value);
+}
+
+// Validate unsigned long SQLUINTEGER return value is greater than
+void ValidateGreaterThan(SQLHDBC connection, SQLUSMALLINT info_type,
+                         SQLUINTEGER compared_value) {
+  SQLUINTEGER info_value;
+  SQLSMALLINT message_length;
+
+  SQLRETURN ret = SQLGetInfo(connection, info_type, &info_value, 0, 
&message_length);
+
+  EXPECT_EQ(SQL_SUCCESS, ret);
+
+  EXPECT_GT(info_value, compared_value);
+}
+
+// Validate unsigned length SQLULEN return value is greater than
+void ValidateGreaterThan(SQLHDBC connection, SQLUSMALLINT info_type,
+                         SQLULEN compared_value) {
+  SQLULEN info_value;
+  SQLSMALLINT message_length;
+
+  SQLRETURN ret = SQLGetInfo(connection, info_type, &info_value, 0, 
&message_length);
+
+  EXPECT_EQ(SQL_SUCCESS, ret);
+
+  EXPECT_GT(info_value, compared_value);
+}
+
+// Validate wchar string SQLWCHAR return value is not empty
+void ValidateNotEmptySQLWCHAR(SQLHDBC connection, SQLUSMALLINT info_type,
+                              bool allow_truncation) {
+  SQLWCHAR info_value[ODBC_BUFFER_SIZE] = L"";
+  SQLSMALLINT message_length;
+
+  SQLRETURN ret =
+      SQLGetInfo(connection, info_type, info_value, ODBC_BUFFER_SIZE, 
&message_length);
+
+  if (allow_truncation && ret == SQL_SUCCESS_WITH_INFO) {
+    EXPECT_EQ(SQL_SUCCESS_WITH_INFO, ret);
+  } else {
+    EXPECT_EQ(SQL_SUCCESS, ret);
+  }
+
+  EXPECT_GT(wcslen(info_value), 0);
+}
+
+// Driver Information
+
+TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoActiveEnvironments) {
+  this->Connect();

Review Comment:
   yes, added separate test fixture `ConnectionInfoTest`



##########
cpp/src/arrow/flight/sql/odbc/tests/connection_info_test.cc:
##########
@@ -0,0 +1,1489 @@
+// 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"
+
+#ifdef _WIN32
+#  include <windows.h>
+#endif
+
+#include <sql.h>
+#include <sqltypes.h>
+#include <sqlucode.h>
+
+#include "gtest/gtest.h"
+
+namespace arrow::flight::sql::odbc {
+
+// Helper Functions
+
+// Validate unsigned short SQLUSMALLINT return value
+void Validate(SQLHDBC connection, SQLUSMALLINT info_type, SQLUSMALLINT 
expected_value) {
+  SQLUSMALLINT info_value;
+  SQLSMALLINT message_length;
+
+  SQLRETURN ret = SQLGetInfo(connection, info_type, &info_value, 0, 
&message_length);
+
+  EXPECT_EQ(SQL_SUCCESS, ret);
+
+  EXPECT_EQ(expected_value, info_value);
+}
+
+// Validate unsigned long SQLUINTEGER return value
+void Validate(SQLHDBC connection, SQLUSMALLINT info_type, SQLUINTEGER 
expected_value) {
+  SQLUINTEGER info_value;
+  SQLSMALLINT message_length;
+
+  SQLRETURN ret = SQLGetInfo(connection, info_type, &info_value, 0, 
&message_length);
+
+  EXPECT_EQ(SQL_SUCCESS, ret);
+
+  EXPECT_EQ(expected_value, info_value);
+}
+
+// Validate unsigned length SQLULEN return value
+void Validate(SQLHDBC connection, SQLUSMALLINT info_type, SQLULEN 
expected_value) {
+  SQLULEN info_value;
+  SQLSMALLINT message_length;
+
+  SQLRETURN ret = SQLGetInfo(connection, info_type, &info_value, 0, 
&message_length);
+
+  EXPECT_EQ(SQL_SUCCESS, ret);
+
+  EXPECT_EQ(expected_value, info_value);
+}
+
+// Validate wchar string SQLWCHAR return value
+void Validate(SQLHDBC connection, SQLUSMALLINT info_type, SQLWCHAR* 
expected_value) {
+  SQLWCHAR info_value[ODBC_BUFFER_SIZE] = L"";
+  SQLSMALLINT message_length;
+
+  SQLRETURN ret =
+      SQLGetInfo(connection, info_type, info_value, ODBC_BUFFER_SIZE, 
&message_length);
+
+  EXPECT_EQ(SQL_SUCCESS, ret);
+
+  EXPECT_EQ(*expected_value, *info_value);
+}
+
+// Validate unsigned long SQLUINTEGER return value is greater than
+void ValidateGreaterThan(SQLHDBC connection, SQLUSMALLINT info_type,
+                         SQLUINTEGER compared_value) {
+  SQLUINTEGER info_value;
+  SQLSMALLINT message_length;
+
+  SQLRETURN ret = SQLGetInfo(connection, info_type, &info_value, 0, 
&message_length);
+
+  EXPECT_EQ(SQL_SUCCESS, ret);
+
+  EXPECT_GT(info_value, compared_value);
+}
+
+// Validate unsigned length SQLULEN return value is greater than
+void ValidateGreaterThan(SQLHDBC connection, SQLUSMALLINT info_type,
+                         SQLULEN compared_value) {
+  SQLULEN info_value;
+  SQLSMALLINT message_length;
+
+  SQLRETURN ret = SQLGetInfo(connection, info_type, &info_value, 0, 
&message_length);
+
+  EXPECT_EQ(SQL_SUCCESS, ret);
+
+  EXPECT_GT(info_value, compared_value);
+}
+
+// Validate wchar string SQLWCHAR return value is not empty
+void ValidateNotEmptySQLWCHAR(SQLHDBC connection, SQLUSMALLINT info_type,
+                              bool allow_truncation) {
+  SQLWCHAR info_value[ODBC_BUFFER_SIZE] = L"";
+  SQLSMALLINT message_length;
+
+  SQLRETURN ret =
+      SQLGetInfo(connection, info_type, info_value, ODBC_BUFFER_SIZE, 
&message_length);
+
+  if (allow_truncation && ret == SQL_SUCCESS_WITH_INFO) {
+    EXPECT_EQ(SQL_SUCCESS_WITH_INFO, ret);
+  } else {
+    EXPECT_EQ(SQL_SUCCESS, ret);
+  }
+
+  EXPECT_GT(wcslen(info_value), 0);
+}
+
+// Driver Information
+
+TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoActiveEnvironments) {
+  this->Connect();
+
+  Validate(this->conn, SQL_ACTIVE_ENVIRONMENTS, static_cast<SQLUSMALLINT>(0));
+
+  this->Disconnect();
+}
+
+#ifdef SQL_ASYNC_DBC_FUNCTIONS
+TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoAsyncDbcFunctions) {
+  this->Connect();
+
+  Validate(this->conn, SQL_ASYNC_DBC_FUNCTIONS,
+           static_cast<SQLUINTEGER>(SQL_ASYNC_DBC_NOT_CAPABLE));
+
+  this->Disconnect();
+}
+#endif
+
+TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoAsyncMode) {
+  this->Connect();
+
+  Validate(this->conn, SQL_ASYNC_MODE, static_cast<SQLUINTEGER>(SQL_AM_NONE));
+
+  this->Disconnect();
+}
+
+#ifdef SQL_ASYNC_NOTIFICATION
+TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoAsyncNotification) {
+  this->Connect();
+
+  Validate(this->conn, SQL_ASYNC_NOTIFICATION,
+           static_cast<SQLUINTEGER>(SQL_ASYNC_NOTIFICATION_NOT_CAPABLE));
+
+  this->Disconnect();
+}
+#endif
+
+TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoBatchRowCount) {
+  this->Connect();
+
+  Validate(this->conn, SQL_BATCH_ROW_COUNT, static_cast<SQLUINTEGER>(0));
+
+  this->Disconnect();
+}
+
+TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoBatchSupport) {
+  this->Connect();
+
+  Validate(this->conn, SQL_BATCH_SUPPORT, static_cast<SQLUINTEGER>(0));
+
+  this->Disconnect();
+}
+
+TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoDataSourceName) {
+  this->Connect();
+
+  Validate(this->conn, SQL_DATA_SOURCE_NAME, (SQLWCHAR*)L"");
+
+  this->Disconnect();
+}
+
+#ifdef SQL_DRIVER_AWARE_POOLING_SUPPORTED
+TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoDriverAwarePoolingSupported) {
+  // A driver does not need to implement SQL_DRIVER_AWARE_POOLING_SUPPORTED 
and the
+  // Driver Manager will not honor to the driver's return value.
+  this->Connect();
+
+  Validate(this->conn, SQL_DRIVER_AWARE_POOLING_SUPPORTED,
+           static_cast<SQLUINTEGER>(SQL_DRIVER_AWARE_POOLING_NOT_CAPABLE));
+
+  this->Disconnect();
+}
+#endif
+
+// These information types are implemented by the Driver Manager alone.
+TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoDriverHdbc) {
+  this->Connect();
+
+  // Value returned from driver manager is the connection address
+  ValidateGreaterThan(this->conn, SQL_DRIVER_HDBC, static_cast<SQLULEN>(0));
+
+  this->Disconnect();
+}
+
+// These information types are implemented by the Driver Manager alone.
+TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoDriverHdesc) {
+  // TODO This is failing due to no descriptor being created
+  // enable after SQL_HANDLE_DESC is supported
+  GTEST_SKIP();
+  this->Connect();
+
+  Validate(this->conn, SQL_DRIVER_HDESC, static_cast<SQLULEN>(0));
+
+  this->Disconnect();
+}
+
+// These information types are implemented by the Driver Manager alone.
+TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoDriverHenv) {
+  this->Connect();
+
+  // Value returned from driver manager is the env address
+  ValidateGreaterThan(this->conn, SQL_DRIVER_HENV, static_cast<SQLULEN>(0));
+
+  this->Disconnect();
+}
+
+// These information types are implemented by the Driver Manager alone.
+TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoDriverHlib) {
+  this->Connect();
+
+  ValidateGreaterThan(this->conn, SQL_DRIVER_HLIB, static_cast<SQLULEN>(0));
+
+  this->Disconnect();
+}
+
+// These information types are implemented by the Driver Manager alone.
+TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoDriverHstmt) {
+  this->Connect();
+
+  // Value returned from driver manager is the stmt address
+  SQLHSTMT local_stmt = this->stmt;
+  SQLRETURN ret = SQLGetInfo(this->conn, SQL_DRIVER_HSTMT, &local_stmt, 0, 0);
+  EXPECT_EQ(SQL_SUCCESS, ret);
+  EXPECT_GT(local_stmt, static_cast<SQLHSTMT>(0));
+
+  this->Disconnect();
+}
+
+TYPED_TEST(FlightSQLODBCTestBase, TestSQLGetInfoDriverName) {
+  this->Connect();
+
+  Validate(this->conn, SQL_DRIVER_NAME, (SQLWCHAR*)L"Arrow Flight ODBC 
Driver");

Review Comment:
   yup, fixed



##########
cpp/src/arrow/flight/sql/odbc/odbc_api.cc:
##########
@@ -185,8 +185,22 @@ SQLRETURN SQLGetInfo(SQLHDBC conn, SQLUSMALLINT info_type, 
SQLPOINTER info_value
                    << ", info_value_ptr: " << info_value_ptr << ", buf_len: " 
<< buf_len
                    << ", string_length_ptr: "
                    << static_cast<const void*>(string_length_ptr);
-  // GH-47709 TODO: Implement SQLGetInfo
-  return SQL_INVALID_HANDLE;
+
+  using ODBC::ODBCConnection;
+
+  return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
+    ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);
+
+    // Set character type to be Unicode by default
+    const bool is_unicode = true;
+
+    if (!info_value_ptr && !string_length_ptr) {
+      return static_cast<SQLRETURN> SQL_ERROR;

Review Comment:
   fixed 👍 



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