Skip to content

fix: Report the server's message when a fetch fails with MariaDB Connector/C - #612

Merged
krlmlr merged 3 commits into
mainfrom
claude/fetch-error-message
Nov 29, 2026
Merged

krlmlr merged 3 commits into
mainfrom
claude/fetch-error-message

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member

Closes #603.

With MariaDB Connector/C as the client library, an error in the middle of a fetch reported only " [0]", because mysql_stmt_error() and mysql_stmt_errno() are empty there. MariaResultPrep::throw_error() now falls back to the connection's mysql_error() and mysql_errno() when the statement has no error number. With libmysqlclient, nothing changes.

The other throw sites were checked: DbConnection already uses mysql_error(), and MariaResultSimple and MariaBinding throw fixed messages. src/MariaRow.cpp (lines 86 and 230) still uses mysql_stmt_error() alone, for errors while binding result buffers and fetching columns. It is left alone because #587 rewrites that file.

Tests

tests/testthat/test-fetch-error.R (new) uses the issue's query and expects "Subquery returns more than 1 row [1242]" from dbGetQuery() and from dbSendQuery() plus dbFetch(). It fails with an unfixed build against MariaDB Connector/C 3.3.17, and passes with this change against both Connector/C 3.3.17 and libmysqlclient 8.0.46. Local runs of the whole suite against MariaDB 10.11 with NOT_CRAN=true, one for each client library, had 0 failures and the one test-timezone.R error ("US/Alaska" unknown to CCTZ in this container), which also happens on main. MySQL servers were 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 first clean review found a Medium: the fallback could call mysql_error() on a closed connection. It is fixed in 6c84eb3, and a second round found nothing above Low.

  • src/MariaResultPrep.cpp: when the statement has no error number, the connection's message is used. It could be stale from an earlier operation on the same connection. Relevance: low, since this needs a statement failure with error number 0. Reviewer confidence: medium.
  • tests/testthat/test-fetch-error.R: on MySQL 8, the subquery error may come at execute rather than mid-fetch, so the test may not exercise the fetch path there. It still checks the message. Relevance: low. Reviewer confidence: medium.
  • dbFetch() after dbDisconnect() crashes with MariaDB Connector/C, a problem that already exists on main and makes the closed-connection branch here unreachable in practice: dbFetch() after dbDisconnect() crashes R with MariaDB Connector/C #615.

Generated by Claude Code

@krlmlr
krlmlr marked this pull request as ready for review November 29, 2026 12:14
@krlmlr
krlmlr merged commit 22d566d into main Nov 29, 2026
9 checks passed
@krlmlr
krlmlr deleted the claude/fetch-error-message branch November 29, 2026 13:58
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.

Error message is lost when a fetch fails in the middle of a result with MariaDB Connector/C

2 participants