Skip to content

fix: dbHasCompleted() and dbGetRowCount() follow dbBind() of a query - #608

Merged
krlmlr merged 2 commits into
mainfrom
claude/bind-has-completed
Nov 29, 2026
Merged

krlmlr merged 2 commits into
mainfrom
claude/bind-has-completed

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member

Closes #602.

Before this change, MariaResultPrep::bind() marked a query's result as complete. dbHasCompleted() was therefore TRUE right after dbBind(), and the usual while (!dbHasCompleted(rs)) dbFetch(rs, n) loop returned no rows. dbGetRowCount() also kept adding up across rebinds.

Change

  • For a query, bind() now runs the first row of parameters at once instead of setting complete_. step() still runs the remaining rows. With no parameter rows, the result is complete.
  • bind() resets the fetched row count, as it already does for the affected row count. dbGetRowCount() therefore counts the rows fetched since the last dbBind().
  • Statements are unchanged.
  • Side effect: a query that fails on execution now errors in dbBind(), not in the first dbFetch().

DBItest misses this because bind_return_value checks dbHasCompleted() and dbGetRowCount() only before dbBind(), and the has_completed_* and row_count_* specs never bind.

The diff in src/MariaResultPrep.cpp is kept minimal because #587 rewrites that file and rebases over this.

Tests

tests/testthat/test-dbBind-completed.R (new) has three standalone tests for the fetch loop and for rebinding queries and statements. Without the fix, 9 of its 26 checks fail. Local run against MariaDB 10.11 with NOT_CRAN=true: the whole suite including DBItest had 0 failures and the one test-timezone.R error ("US/Alaska" unknown to CCTZ in this container), which also happens on main. MySQL was not tested: there is no server in this container, and 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.

  • src/MariaResultPrep.cpp: an error from the first row of parameters now surfaces in dbBind(), not in the first dbFetch(). This matches statements, and the NEWS line that dbSendQuery() clears the result if dbBind() throws. Relevance: low. Reviewer confidence: high.
  • tests/testthat/test-dbBind-completed.R: the third test clears its result without on.exit(), so a failing expectation would leave the result open until the connection closes. Relevance: low. Reviewer confidence: high.
  • A failed rebind leaves the result stuck with "Commands out of sync", a problem that already exists on main: A failed rebind leaves the result stuck with "Commands out of sync" #614, to be fixed in a PR stacked on this one.
  • With libmysqlclient, a rebind before all rows were fetched was checked against the library's source only, not run. With MariaDB Connector/C, it was run.

Generated by Claude Code

@krlmlr
krlmlr marked this pull request as ready for review November 29, 2026 12:08
@krlmlr
krlmlr added this pull request to stack #619 November 29, 2026 12:13
@krlmlr
krlmlr merged commit ec30d08 into main Nov 29, 2026
9 checks passed
@krlmlr
krlmlr deleted the claude/bind-has-completed 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.

dbHasCompleted() is TRUE right after dbBind() of a query, and dbGetRowCount() is not reset on rebind

2 participants