Skip to content

fix(rust/ffi): set rows_affected to -1 on the query path of ExecuteQuery#4469

Merged
lidavidm merged 1 commit into
apache:mainfrom
fornwall:fix-execute-query-rows-affected
Jul 7, 2026
Merged

fix(rust/ffi): set rows_affected to -1 on the query path of ExecuteQuery#4469
lidavidm merged 1 commit into
apache:mainfrom
fornwall:fix-execute-query-rows-affected

Conversation

@fornwall

@fornwall fornwall commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

statement_execute_query wrote rows_affected only on the update path (out == NULL). On the query path it left the caller's out-parameter untouched, so callers read back whatever they passed in. ADBC's AdbcStatementExecuteQuery contract (adbc.h) defines rows_affected as the row count if known, else -1; write that sentinel in the query branch.

Adds a C-ABI regression test (via the dummy driver's exported vtable, since the Rust driver manager passes a NULL rows_affected for queries so the value is not observable through the high-level API).

Closes #4468.

@fornwall fornwall requested a review from wjones127 as a code owner July 6, 2026 17:12
fornwall added a commit to fornwall/adbc-spanner that referenced this pull request Jul 6, 2026
* Pin adbc_core/adbc_ffi to a fork with two fixes; bump arrow to 59

Switches the ADBC crates from crates.io 0.23 to a git pin on
fornwall/arrow-adbc carrying two fixes absent from the 0.23 release:

  1. release_ffi_error is idempotent — it nulls the AdbcError's message,
     private_data and release after freeing, so a second release (the
     standard `if (error.release) error.release(&error)` idiom) is a safe
     no-op rather than a double-free. Already on arrow-adbc main; only
     missing from 0.23.
  2. AdbcStatementExecuteQuery writes rows_affected = -1 on the query path
     instead of leaving the caller's out-parameter untouched. Submitted
     upstream as apache/arrow-adbc#4469.

Because the git pin's adbc crates allow arrow >=58,<60, bump arrow to
59.x (was pinned <59 for the 0.23 crates).

Effect on the C++ adbc_validation suite (run against the driver's C ABI):
the fixes remove the process-aborting double-free on error-path tests and
make queries report rows_affected = -1, so four more StatementTest cases
pass cleanly (SqlQueryInts, SqlQueryStrings, SqlPrepareSelectNoParams,
SqlPrepareErrorNoQuery). The gate grows from 31 to 35 passing tests; the
README's follow-up categorization and the now-obsolete "failures abort
the process" note are updated accordingly.

Also carries the one salvageable improvement from the superseded #10:
prepare() now accepts a bulk-ingest target (target set, no SQL) instead
of wrongly returning InvalidState, with a test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013X531Vx36F5vyUSVidayPd

* Allow the arrow-adbc git source in deny.toml; refresh lockfile

cargo-deny failed with source-not-allowed for the three adbc_* crates now
pinned to git — add https://github.com/fornwall/arrow-adbc to the
[sources] allow-git list (alongside the google-cloud fork).

Also refresh Cargo.lock to the latest compatible versions (`cargo
update`), which moves num-bigint off the yanked 0.4.7 -> 0.4.8 and bumps
a handful of transitive patch releases. All direct dependencies are
already on their latest major (arrow is capped at <60 by the pinned adbc
crates), so there are no Cargo.toml major bumps to make.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013X531Vx36F5vyUSVidayPd

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@lidavidm lidavidm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just a nit about the redundant comment

Comment thread rust/ffi/src/driver_exporter.rs Outdated
`statement_execute_query` wrote `rows_affected` only on the update path
(`out == NULL`). On the query path it left the caller's out-parameter
untouched, so callers read back whatever they passed in. ADBC's
`AdbcStatementExecuteQuery` contract (adbc.h) defines `rows_affected` as
the row count if known, else -1; write that sentinel in the query branch.

Adds a C-ABI regression test (via the dummy driver's exported vtable,
since the Rust driver manager passes a NULL `rows_affected` for queries
so the value is not observable through the high-level API).

Signed-off-by: Fredrik Fornwall <fredrik@fornwall.net>
@fornwall fornwall force-pushed the fix-execute-query-rows-affected branch from 21b110f to 289ed79 Compare July 7, 2026 07:50
@fornwall

fornwall commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! I applied your suggestions which removed the comment and squashed the commits.

@fornwall

fornwall commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

CI failures seems unrelated to changes here? https://github.com/apache/arrow-adbc/actions/runs/28850435930/job/85565046218?pr=4469

[ 92%] Building C object driver/sqlite/CMakeFiles/adbc_driver_sqlite_objlib.dir/statement_reader.c.o
[ 92%] Building CXX object driver/sqlite/CMakeFiles/adbc_driver_sqlite_objlib.dir/sqlite.cc.o
/Users/runner/work/arrow-adbc/arrow-adbc/c/driver/sqlite/sqlite.cc:784:16: error: use of undeclared identifier 'sqlite3_load_extension'
784 | int rc = sqlite3_load_extension(conn_, extension_path_.c_str(),
| ^~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [driver/sqlite/CMakeFiles/adbc_driver_sqlite_objlib.dir/sqlite.cc.o] Error 1
make[1]: *** [driver/sqlite/CMakeFiles/adbc_driver_sqlite_objlib.dir/all] Error 2
make: *** [all] Error 2

@fornwall

fornwall commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Opened the issue #4470 and the proposed fix #4471 for the CI failures noticed in this PR (but unrelated to the changes in it).

@lidavidm lidavidm merged commit 049b336 into apache:main Jul 7, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

adbc_ffi: AdbcStatementExecuteQuery never sets rows_affected on the query path

2 participants