Repository navigation
fix: Read result types after dbBind(), so that placeholder columns keep their values - #618
Conversation
…keep their values Closes #604. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
Keep the first parameter set executed in bind() as in #608, and read the result metadata again right after that execution (#604). 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
Question: Placeholder expressions that are all
|
Only columns that the server reports as NULL at prepare time, such as `SELECT ? AS x`, take their type from the metadata after execution. All other columns keep their prepare-time type, so that `SELECT ? + 1` returns doubles as before, and a real zero-length binary column stays a blob. A column that is still NULL after execution is read as character only if the first parameter set has a NULL parameter, so that `SELECT NULL AS n, ? AS y` keeps `n` integer. A type change in a later parameter set is still an error. The error leaves the column types unchanged and skips the remaining parameter sets, so that the result stays usable. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
MariaRow::value_raw() took `&buffers_[j][0]` of the column buffer,
which is empty for a zero-length BLOB value,
so the access was out of bounds and aborted with _GLIBCXX_ASSERTIONS
(as in the covr job) for `SELECT CAST('' AS BINARY(0)) AS b, ? AS y`.
Use `buffers_[j].data()`, which is valid for an empty vector.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
A result column that the server reports as NULL after the first execution was read as character whenever any parameter of the first set was NULL. With an NA integer parameter, this made `SELECT NULL AS n, ?` return a character `n`, and `SELECT IF(?, ?, ?)` fail with a type mismatch once a later set reported an integer. Fall back to character only for a NULL character or blob parameter, and read the column as integer otherwise, as for a plain `SELECT NULL`. Also free the result metadata in update_metadata() before computing the types, so that a warning turned into an error does not leak it, and restrict the comment on the mismatch error to placeholder columns. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
Accepted limitationsThree review rounds. The first found a High:
Generated by Claude Code |
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
Closes #604. Stacked on #608, which makes
bind()execute the first set of parameters.Before this change, result types were fixed when the statement was prepared. A column that is just a placeholder, as in
SELECT ? AS s, has typeNULLat prepare time and was read as an integer, so afterdbBind()a string came back as0, 1.5 as1, and a date as a number.Change
send_query()records which result columns have typeNULLat prepare time, which is the case for a column that is just a placeholder. After each set of parameters runs,update_metadata()reads the metadata again and updates the types of those columns only, and sets up the output bindings again if they changed. All other columns keep their prepare-time types, so for exampleSELECT ? + 1still returns a double forc(NA, 1L)and for1:2, and a realBINARY(0)column stays a blob.dbColumnInfo()beforedbBind()still reportsintegerfor a placeholder column, because the type isn't known yet. AfterdbBind(), it reports the parameter's type, also after a rebind with another type.dbFetch()appends every set to one data frame, so the first set's types win. If a later set gives a placeholder column another type, asSELECT IF(?, ?, ?)can,dbFetch()raises an error that names the column and suggestsCAST(). The result is then marked complete and the remaining sets are skipped, so that a laterdbFetch()returns no rows instead of misreading values, and a newdbBind()works.NULL, or a zero-length binary string, after a first set with aNULLparameter, it is read as character. MariaDB 10.11 reports the bound type in that case with both client libraries, so this is a fallback for other servers. See the question below.Tests
tests/testthat/test-dbBind-types.R(new) covers string, double, date andNULLparameters inSELECT ? AS x, a rebind with another type, and a multi-row bind. It also coversSELECT ? + 1,BINARY(0)columns, a literalNULLcolumn next to a placeholder, and the type-mismatch error. Its 25 expectations pass with libmysqlclient 8.0.46 and MariaDB Connector/C 3.3.17. Local runs against MariaDB 10.11 withNOT_CRAN=true, with each client library: the whole suite had 0 failures and the onetest-timezone.Rerror ("US/Alaska" unknown to CCTZ in this container), which also happens onmain. 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