Repository navigation
fix: Type placeholder result columns after each execution and re-prepare on a parameter type change - #656
Draft
krlmlr wants to merge 11 commits into
Draft
fix: Type placeholder result columns after each execution and re-prepare on a parameter type change#656krlmlr wants to merge 11 commits into
krlmlr wants to merge 11 commits into
Conversation
…ameter type change (#638) The result columns of a query with parameters now take their types from the metadata the server reports after each execution. MySQL reports `?` as a string at prepare time, and a DOUBLE bound as a string came back as "" or "0". A MySQL server keeps the result types of a statement from its first execution, so `dbBind()` prepares the statement again when a parameter has another type than its last non-NULL value. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
) Tests of 1.5, 0.1, dates, long strings and a type change across `dbBind()` calls run on both servers. Integer, blob and leading-NA placeholders, and `IF(?, ?, ?)`, stay MariaDB-only. Known column types come from a typed temporary table, and the empty-names test uses `CAST()`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
…ders-v2 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd43pnoHuAnGBgMih89
A NULL parameter can change the type of an expression over it, such as `? + 1`, which made several parameter sets with an NA fail with a type mismatch. A first set with a NULL parameter keeps the prepare-time type of columns known at prepare time, and later sets may change it to a type that converts without loss. In a later set with a NULL parameter, a column of another type is fine as long as its values are NULL. A new prepare on a parameter type change now goes into a new statement handle, so that a failure leaves the previous statement intact. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd43pnoHuAnGBgMih89
…rs (#638) Restores the `SELECT ? + 1` tests with an NA, adds ABS() and UPPER(), pins what a leading NA in a placeholder column gives on MariaDB and MySQL servers and states it exactly in ?dbBind, and adds back an integer case for #599. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd43pnoHuAnGBgMih89
Member
Author
Question: A leading
|
…all others (#638) Columns that are not just a placeholder keep their type from prepare time again, as on main, so that `SELECT ? + 1`, `ABS(?)`, `UPPER(?)` or `DATE_ADD(?, ...)` return the same types as before whatever the position of an NA, and an NA of one parameter no longer changes the type of another column. A placeholder column is one of type NULL at prepare time, or with a MySQL server one of a non-binary string type. A later parameter set that gives a placeholder column another type is an error only when it returns a value that is not NULL in that column. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd43pnoHuAnGBgMih89
Covers `? + 1`, `ABS()`, `CONCAT()`, `COALESCE()`, `UPPER()` and `DATE_ADD()` with a leading and a trailing NA, and an NA of one parameter next to another column, with main's types on MariaDB servers. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd43pnoHuAnGBgMih89
krlmlr
pushed a commit
that referenced
this pull request
Nov 29, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd43pnoHuAnGBgMih89
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #638, rebuilt from the findings of the plain-C experiment #646, as asked on #641. It replaces #641, which is closed now.
Design, following variant c5 of #646, the only one that was right on all four server × client combinations:
mysql_stmt_result_metadata()). A DOUBLE is therefore never bound as a string, and the empty string buffer can't truncate it any more: 1.5 no longer comes back as""on MySQL. fix: Read result types afterdbBind(), so that placeholder columns keep their values #618's handling of columns that are NULL at prepare time stays, and a type change between parameter sets is still an error.? + 1is BIGINT for a value but INT for NULL. So if the first set has a NULL parameter, a column with a type at prepare time keeps that type, and a later set may change it only to a type that the client library converts without loss (an integer to DOUBLE or BIGINT, a string to a blob). In a later set with a NULL parameter, a column of another type is fine as long as its values are NULL; a non-NULL value there is the usual type-mismatch error. Without this,SELECT ? + 1withc(1L, NA),ABS(?)withc(-1L, NA)andUPPER(?)withc("ab", NA)failed on MariaDB.dbBind()prepares the statement again when a parameter's type differs from its last non-NULL value. This avoids MySQL keeping a reused statement's type, where'abc'after 1.5 came back as0. The new prepare goes into a new statement handle, so a failure leaves the previous statement intact.?dbBinddescribes what still differs on MySQL servers.A visible change on MariaDB:
SELECT ? + 1with an integer parameter now returnsinteger64(BIGINT, what the server reports after execution, and what MySQL returns too) rather than double; with a leading NA it stays double.UPPER(?)with a leading NA still returns a blob on MariaDB, as onmain.Tests:
test-fetch-length.R), and the type change'abc'→ 2.5 →'abc', also with unfetched rows. Also a typedTEMPORARYtable for known column types,CAST()in the empty-names test plus an integer case fordbBind()rejects parameters whose names are all empty #599, doubles in thedbHasCompleted()isTRUEright afterdbBind()of a query, anddbGetRowCount()is not reset on rebind #602 tests, and? + 1,ABS(?)andUPPER(?)with an NA in the first or a later set, compared as numbers where the servers' types differ.SELECT ? AS xwithc(NA, 0.1, 2.5)returnsc(NA, 0.1, 2.5)(double) and withc(NA, 1L, 2L)returnsc(NA, 1L, 2L)(integer), also with the MySQL client library. With a MySQL server, both fail: "Columnxhas type double (resp. integer64) for this set of parameters, but string for the first one."?dbBindnow states exactly that. This behaviour is the open question that moved here from fix: Correct values and parameter types for placeholder columns with MySQL servers #641.integer64(BIGINT), blobs as character, and a NULL gives no type.Status: draft. The full matrix (run 46314093558, dispatched by hand because same-repository pull requests run only the smoke test) is green on 42c2ff2, and every job that ran the tests has
FAIL 0in its log: "MySQL server" (MySQL 8.4)[ FAIL 0 | WARN 2 | SKIP 31 | PASS 9193 ], "MariaDB server, MySQL client" and "MariaDB server + client"[ FAIL 0 | WARN 2 | SKIP 15 | PASS 9231 ], and the macOSmysql_configandmariadb_configjobsPASS 9226. The warnings are the garbage-collected-connection warnings also seen onmain. The "windows-latest (4.3)" and "(4.4)" jobs are green but never ran R CMD check: rcmdcheck stops at once withError in `[.data.frame`(file.info(foo), , "uname"). This is a CI problem that also shows on earlier runs. Locally the suite passes against MariaDB 10.11 (FAIL 0 | PASS 9231) and MySQL 8.0 (FAIL 0 | SKIP 31 | PASS 9193), both with the MariaDB client. The new-handle prepare is not covered by a test, because a failing prepare can't be provoked without a metadata lock.Left to do:
https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
https://claude.ai/code/session_01Hr1rd43pnoHuAnGBgMih89 (now driving this PR)
Generated by Claude Code