justing-bq commented on code in PR #47788:
URL: https://github.com/apache/arrow/pull/47788#discussion_r2437467760


##########
cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.cc:
##########
@@ -0,0 +1,475 @@
+// 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.
+
+// For DSN registration. flight_sql_connection.h needs to included first due 
to conflicts
+// with windows.h
+#include "arrow/flight/sql/odbc/odbc_impl/flight_sql_connection.h"
+
+#include "arrow/flight/sql/odbc/tests/odbc_test_suite.h"
+
+// For DSN registration
+#include "arrow/flight/sql/odbc/odbc_impl/config/configuration.h"
+#include "arrow/flight/sql/odbc/odbc_impl/encoding_utils.h"
+#include "arrow/flight/sql/odbc/odbc_impl/odbc_connection.h"
+
+namespace arrow::flight::sql::odbc {
+namespace tests {
+
+void FlightSQLODBCRemoteTestBase::AllocEnvConnHandles(SQLINTEGER odbc_ver) {
+  // Allocate an environment handle
+  EXPECT_EQ(SQL_SUCCESS, SQLAllocEnv(&env));
+
+  EXPECT_EQ(
+      SQL_SUCCESS,
+      SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION,
+                    
reinterpret_cast<SQLPOINTER>(static_cast<intptr_t>(odbc_ver)), 0));
+
+  // Allocate a connection using alloc handle
+  EXPECT_EQ(SQL_SUCCESS, SQLAllocHandle(SQL_HANDLE_DBC, env, &conn));
+}
+
+void FlightSQLODBCRemoteTestBase::Connect(SQLINTEGER odbc_ver) {
+  AllocEnvConnHandles(odbc_ver);
+  std::string connect_str = GetConnectionString();
+  ConnectWithString(connect_str);
+}
+
+void FlightSQLODBCRemoteTestBase::ConnectWithString(std::string connect_str) {
+  // Connect string
+  std::vector<SQLWCHAR> connect_str0(connect_str.begin(), connect_str.end());
+
+  SQLWCHAR out_str[ODBC_BUFFER_SIZE];
+  SQLSMALLINT out_str_len;
+
+  // Connecting to ODBC server.
+  SQLRETURN ret = SQLDriverConnect(conn, NULL, &connect_str0[0],
+                                   
static_cast<SQLSMALLINT>(connect_str0.size()), out_str,
+                                   ODBC_BUFFER_SIZE, &out_str_len, 
SQL_DRIVER_NOPROMPT);
+  if (ret != SQL_SUCCESS) {
+    std::cerr << GetOdbcErrorMessage(SQL_HANDLE_DBC, conn) << std::endl;
+  }
+
+  // Assert connection is successful before we continue
+  ASSERT_EQ(SQL_SUCCESS, ret);
+
+  // Allocate a statement using alloc handle
+  ASSERT_EQ(SQL_SUCCESS, SQLAllocHandle(SQL_HANDLE_STMT, conn, &stmt));
+}
+
+void FlightSQLODBCRemoteTestBase::Disconnect() {
+  // Close statement
+  EXPECT_EQ(SQL_SUCCESS, SQLFreeHandle(SQL_HANDLE_STMT, stmt));
+
+  // Disconnect from ODBC
+  SQLRETURN ret = SQLDisconnect(conn);
+  if (ret != SQL_SUCCESS) {
+    std::cerr << GetOdbcErrorMessage(SQL_HANDLE_DBC, conn) << std::endl;
+  }

Review Comment:
   Done.



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