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


##########
cpp/src/arrow/flight/sql/odbc/odbc_api.cc:
##########
@@ -36,26 +36,173 @@ SQLRETURN SQLAllocHandle(SQLSMALLINT type, SQLHANDLE 
parent, SQLHANDLE* result)
   ARROW_LOG(DEBUG) << "SQLAllocHandle called with type: " << type
                    << ", parent: " << parent
                    << ", result: " << static_cast<const void*>(result);
-  // GH-46096 TODO: Implement SQLAllocEnv
-  // GH-46097 TODO: Implement SQLAllocConnect, pre-requisite requires 
SQLAllocEnv
-  // implementation
-
-  // GH-47706 TODO: Implement SQLAllocStmt, pre-requisite requires
+  // GH-47706 TODO: Add tests for SQLAllocStmt, pre-requisite requires
   // SQLDriverConnect implementation
 
-  // GH-47707 TODO: Implement SQL_HANDLE_DESC for
+  // GH-47707 TODO: Add tests for SQL_HANDLE_DESC implementation for
   // descriptor handle, pre-requisite requires SQLAllocStmt
-  return SQL_INVALID_HANDLE;
+
+  *result = nullptr;
+
+  switch (type) {
+    case SQL_HANDLE_ENV: {
+      using driver::flight_sql::FlightSqlDriver;
+      using ODBC::ODBCEnvironment;
+
+      *result = SQL_NULL_HENV;
+
+      try {
+        static std::shared_ptr<FlightSqlDriver> odbc_driver =
+            std::make_shared<FlightSqlDriver>();
+        *result = reinterpret_cast<SQLHENV>(new ODBCEnvironment(odbc_driver));
+
+        return SQL_SUCCESS;
+      } catch (const std::bad_alloc&) {
+        // allocating environment failed so cannot log diagnostic error here
+        return SQL_ERROR;
+      }
+    }
+
+    case SQL_HANDLE_DBC: {
+      using ODBC::ODBCConnection;
+      using ODBC::ODBCEnvironment;
+
+      *result = SQL_NULL_HDBC;
+
+      ODBCEnvironment* environment = 
reinterpret_cast<ODBCEnvironment*>(parent);
+
+      return ODBCEnvironment::ExecuteWithDiagnostics(environment, SQL_ERROR, 
[=]() {
+        std::shared_ptr<ODBCConnection> conn = environment->CreateConnection();
+
+        if (conn) {
+          *result = reinterpret_cast<SQLHDBC>(conn.get());
+
+          return SQL_SUCCESS;
+        }

Review Comment:
   I think this needs to be noted inline; as-is this looks suspicious to anyone 
reading the code later



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