Skip to content

Source: derived parameter names are resolved on every run, so a reused command sends the right names - #168

Merged
electricessence merged 3 commits into
masterfrom
feat/a6-params-r20
Nov 16, 2026
Merged

electricessence merged 3 commits into
masterfrom
feat/a6-params-r20

Conversation

@electricessence

Copy link
Copy Markdown
Collaborator

What this changes

A command that gets its parameter names from the database (a stored procedure called with AddParam(value) and no names) resolved those names once and wrote them into the command's Params. A second run on the same command object then reused the first run's names: after a connection change, a different database or a different procedure, it sent the wrong names (SQL Server: "Procedure ... expects parameter '@p_order_id', which was not supplied"). This fixes it with no public or protected change.

What changes inside. The derived names are resolved on every run into a per-run send list, and Params is never rewritten: it keeps what the caller added. The unchanged AddParams(TCommand) hook still sees the resolved list through Params while that command's PrepareCommand runs on that thread. That uses thread-static state (Preparing, SendList, SpareList) that is reset in a finally, restores the previous values for nested prepares, and keeps concurrent runs of one command object safe. A command with no derived names takes today's path with one field read. Only ExpressiveCommandBase.cs changed in Source/.

  • Public API: the diff is empty. No public or protected member is added or changed, and the four AddParams(TCommand) overrides are not edited.
  • The one visible change. After a run, Params shows what the caller added; before, it showed the resolved names. expressive-commands.md said the second; the sentence is rewritten, and the migration notes carry a line. What was sent is readable through Execute(command => ...).
  • Cost. A reused derived command allocates 168 bytes per run, the same as a command with explicit names (sync, async, and AddParams with an object). A reused command whose provider reports no names now asks the provider on every run instead of once (the provider's lookup is a schema query for the database-connection command); commands created per call are unchanged.
  • Tests. 25 new tests: a fake provider (18), LocalDB stored procedures on two databases with a procedure created and dropped per test (4, they fail rather than skip when LocalDB is missing), and allocation (3). On master's source 17 of the 24 new tests fail, including the SQL Server error above. One existing test is renamed to say Params is still what was added after a run.

Checks

  • Release build of the whole solution with 0 warnings; the public-API analyzer reports nothing.
  • The full test gate (Core tests on net10.0 and net11.0, the legacy-compiler tests, the samples) and a Visual Studio MSBuild of the solution are green; leak scan clean.

🤖 Generated with Claude Code

electricessence and others added 3 commits November 16, 2026 11:12
…e Params (R20)

A command object run again against another database (a factory that hands out connections to several, or ChangeDatabase) sent the first run's parameter names and lost the members of an AddParams object that the first procedure did not take, because the first run cached its answer by rewriting Params in place and clearing the derived flag. SQL Server rejected the second run (error 201 or 8145). The name memory (keyed by server, database and procedure) was already right; only the mutation was wrong. Now Params is never written by a run: the names are resolved in every run for the connection that run uses, and the send list is built per thread, set up and reset in one synchronous stretch around the unchanged AddParams(TCommand) hook, which still sees the resolved names through the Params getter. No public or protected member changes. After a run, Params shows what was added, not the resolved names.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…the multi-line ifs (A6 style findings)

Rename the three thread-static fields of ExpressiveCommandBase to _preparing, _sendList and _spareList, and add braces to four multi-line if statements, as the style gate asks. No behaviour change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@electricessence
electricessence marked this pull request as ready for review November 16, 2026 22:40
@electricessence
electricessence merged commit 7cd0dea into master Nov 16, 2026
7 checks passed
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.

1 participant