Skip to content

fix: A failed rebind leaves the result unbound instead of out of sync - #620

Merged
krlmlr merged 3 commits into
claude/bind-result-typesfrom
claude/bind-rebind-error
Nov 29, 2026
Merged

krlmlr merged 3 commits into
claude/bind-result-typesfrom
claude/bind-rebind-error

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member

Closes #614. Stacked on #618, which is stacked on #608; all three change MariaResultPrep::bind().

Before this change, a rebind that failed on execution left the result marked as bound from the earlier bind. dbHasCompleted() returned FALSE, and every later dbFetch() failed, with "Commands out of sync" (MariaDB Connector/C) or "Attempt to read a row while there is no result set" (libmysqlclient).

Change

bind() now marks the result as unbound before it executes anything, and as bound only once the execution succeeded. After a failed rebind, dbFetch() says "Query needs to be bound before fetching", and a later successful dbBind() works as before.

Tests

tests/testthat/test-dbBind-error.R (new) uses a subquery that returns two rows for one parameter value. It fails at execute time, so the test needs no table, lock or second connection. The test checks the error, the unbound state, and that a later rebind works. Its 6 expectations fail without the fix. Local run against MariaDB 10.11 with NOT_CRAN=true, linked to MariaDB Connector/C: before the merge with #618's branch, the whole suite had 0 failures and the one test-timezone.R error ("US/Alaska" unknown to CCTZ in this container), which also happens on main. After the merge, the three test-dbBind-*.R files pass. libmysqlclient and MySQL servers were not tested with this change; CI's MySQL entries currently run MariaDB (#592).

Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ


Generated by Claude Code

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Accepted limitations

The clean review found nothing above Low. It checked both client libraries.

  • src/MariaResultPrep.cpp: the result is marked unbound before the parameter checks. A dbBind() with parameters on a query that has none ("Query has no parameters") now leaves that result unbound, where before it stayed fetchable. Relevance: low, since the call is an error either way. Reviewer confidence: high.
  • A statement whose second row of parameters fails, for example with a duplicate key, has already applied its first row. dbGetRowsAffected() now reports NA, where before it reported a stale count. Neither shows the partial effect. Relevance: low. Reviewer confidence: high.
  • After a failed first execution, dbColumnInfo() reports the types of the previous bind until the next successful one. Relevance: low, no functional impact. Reviewer confidence: high.
  • tests/testthat/test-dbBind-error.R: it covers queries only, not a statement that fails partway, and it relies on the English server message. Relevance: low. Reviewer confidence: high.
  • dbBind() on a result cancelled by a newer query crashes R, a problem that already exists on main: dbBind() on a result cancelled by a newer query crashes R #622.

Generated by Claude Code

@krlmlr
krlmlr marked this pull request as ready for review November 29, 2026 12:17
@krlmlr
krlmlr merged commit c956888 into main Nov 29, 2026
9 checks passed
@krlmlr
krlmlr deleted the claude/bind-rebind-error branch November 29, 2026 13:54
krlmlr pushed a commit that referenced this pull request Nov 29, 2026
update_metadata() from #618 is now the single path for the metadata after an execution.
It replaces setup_output():
its first call caches names, types and the column info and sets up the output binding,
also when the metadata appears only after mysql_stmt_execute().
For the first parameter set it also updates the column info of the placeholder columns,
so that the chunk takes its types from the latest execution,
and later sets keep the types of the first set or raise #618's error.

MariaRow.cpp keeps the chunk version of the row code;
the .data() fix of #618 for empty buffers is already part of it.
bind() keeps #608 and #620 as on main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
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.

A failed rebind leaves the result stuck with "Commands out of sync"

2 participants