amoeba opened a new pull request, #50668:
URL: https://github.com/apache/arrow/pull/50668

   ## Summary
   
   Fixes #50578 — **HY010 `[Apache Arrow][Flight SQL] (100) Function sequence 
error`** when using `CommandBehavior.SchemaOnly` (e.g. schema discovery by Bold 
Reports) with the Arrow Flight SQL ODBC driver against **InfluxDB 3**.
   
   ### Root cause
   
   The FlightSQL spec makes `dataset_schema` in 
`ActionCreatePreparedStatementResult` **optional**. Servers that don't return 
it (InfluxDB 3 is one example) cause the Arrow C++ client to leave 
`PreparedStatement::dataset_schema()` as `nullptr`.
   
   `FlightSqlResultSetMetadata::GetColumnCount()` called 
`schema_->num_fields()` unconditionally, which **crashed** (null-pointer 
dereference) inside `ODBCStatement::Prepare()` — before `is_prepared_` was set 
to `true`.
   
   On Windows, with .NET's ODBC provider, `CommandBehavior.SchemaOnly` calls 
`SQLPrepare` but **not** `SQLExecute`. When `SQLPrepare` crashes and 
`is_prepared_` is never set, any subsequent path that calls `SQLExecute` hits 
the guard in `ODBCStatement::ExecutePrepared()`:
   
   ```cpp
   if (!is_prepared_) {
       throw DriverException("Function sequence error", "HY010");
   }
   ```
   
   producing the error the user sees.
   
   ### Fix
   
   1. **`FlightSqlResultSetMetadata::GetColumnCount()`** — return 0 when 
`schema_` is `nullptr` instead of crashing.
   2. **`FlightSqlStatement::Prepare()`** — return `boost::none` when 
`dataset_schema` is null, so `ODBCStatement::Prepare()` leaves the IRD with 0 
columns but still sets `is_prepared_ = true`. `SQLNumResultCols` returns 0; 
`CommandBehavior.SchemaOnly` readers see an empty schema instead of a driver 
crash followed by a spurious `HY010`.
   
   ### Cross-platform build fixes (macOS / non-MSVC)
   
   The ODBC driver was hard-gated to MSVC-only by `DefineOptions.cmake`. To be 
able to write and run tests on macOS these were also fixed:
   - Remove the Windows-only gate (the core SPI is portable with 
libiodbc/unixodbc).
   - Add `Boost::locale` as a component for all platforms, not just MSVC.
   - Suppress pre-existing clang warnings in `odbcabstraction` / 
`arrow_odbc_spi_impl`.
   - Fix stale 2-arg `GetTypeName()` call in `odbc_descriptor.cc`.
   - Fix `DWORD`→`socklen_t` cast in `address_info.cc` for non-Windows builds.
   - Add missing `#include <limits.h>` / `<string.h>` in the macOS `whereami` 
path.
   
   ### Tests
   
   New test suite `FlightSqlResultSetMetadataTest` with 4 cases:
   - `NullSchemaGetColumnCountReturnsZero` — the null-crash regression test
   - `NullSchemaConstructionDoesNotThrow` — construction with nullptr schema
   - `ValidSchemaGetColumnCount` — baseline, schema with 3 columns
   - `ValidSchemaGetColumnName` — column name access
   
   ```
   [==========] Running 84 tests from 18 test suites ran.
   [  PASSED  ] 84 tests.
   ```
   
   ### Related issues
   - Closes #50578
   - InfluxDB 3 is the server reported by the user 
(`influxdb3-core-3.10.0-windows_amd64`)
   - Driver version: 0.9.7.1195, .NET 10, Windows x64
   


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