Repository navigation
Fix unbound parameter reporting for prefix-less and positional parameters - #39371
Merged
AndriySvyryd merged 3 commits intoOct 26, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The matching fallback can hide a genuinely unbound parameter when the supplied name already has a prefix.
1 open issue
What changed in this PR
This PR addresses #39370 by improving missing-parameter diagnostics in Microsoft.Data.Sqlite.
Changes:
- Adds name matching for parameters supplied without a prefix.
- Reports missing parameters when the collection is uninitialized and displays unnamed parameters as
?. - Adds regression tests for these diagnostic scenarios.
| File | Description |
|---|---|
| test/Microsoft.Data.Sqlite.Tests/SqliteCommandTest.cs | Tests prefix-less, uninitialized-collection, and positional parameter diagnostics. |
| src/Microsoft.Data.Sqlite.Core/SqliteParameter.cs | Adds parameter-name matching for missing-parameter detection. |
| src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs | Uses the matcher and populates previously empty diagnostic entries. |
Review effort: Balanced
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
AndriySvyryd
approved these changes
Oct 26, 2026
AndriySvyryd
left a comment
Member
There was a problem hiding this comment.
Thanks for your contribution!
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 #39370
In
SqliteCommand.GetStatements(), whenexpectedParams != boundParams, unbound parameters are gathered to populate the error message. Currently, it checks!_parameters.Cast<SqliteParameter>().Any(p => p.ParameterName == name).This causes several issues:
cmd.Parameters.AddWithValue("Parameter", 1)), SQLite binds them successfully viaFindPrefixedParameter, but the exact-equality check against@Parameterfails. As a result, already-bound parameters are reported as unbound in the exception message if any other parameter is missing._parameterswas not initialized (_parameters == null), the block was skipped entirely, throwing an exception with an empty missing parameter list.?) have a null name insqlite3_bind_parameter_name, causing null entries inunboundParamsand resulting in empty strings or dangling commas in the message.This change:
Matches(string? name)method onSqliteParameterthat matches both exact names and prefix-less names against@,$, and:prefixed statement parameters.Matcheswhen collecting unbound parameters inSqliteCommand.unboundParamseven when_parameters == null."?"whensqlite3_bind_parameter_namereturns null for positional parameters.