X Tutup
Skip to content

Improve output parameter handling#5645

Merged
NinoFloris merged 4 commits intomainfrom
output-parameter-handling
Nov 10, 2025
Merged

Improve output parameter handling#5645
NinoFloris merged 4 commits intomainfrom
output-parameter-handling

Conversation

@NinoFloris
Copy link
Copy Markdown
Member

@NinoFloris NinoFloris commented Mar 25, 2024

Moved the output reading into the command itself and added support via a virtual for reading values as a generic type for generic parameters.

Probably want to add some tests for the latter, TODO.

Regarding

    // Not sure where this odd behavior comes from: all output parameters which did not get matched by
    // name now get populated with column values which weren't matched. Keeping this for backwards compat,
    // opened #2252 for investigation.

I've added commentary on why it exists, people likely depend on this behavior as well. An unfortunate holdover from when we didn't have positional parameters.

We also have a test depending on it https://github.com/npgsql/npgsql/blob/main/test/Npgsql.Tests/FunctionTests.cs#L119.
Note how the set consists of named parameters while the columns are unnamed.

Closes #2252

@NinoFloris NinoFloris added this to the 9.0.0 milestone Mar 25, 2024
@NinoFloris NinoFloris force-pushed the output-parameter-handling branch 4 times, most recently from 2a86b31 to 5fb2d86 Compare March 28, 2024 18:21
@NinoFloris NinoFloris force-pushed the output-parameter-handling branch from 5fb2d86 to 42bc515 Compare June 24, 2024 23:17
@vonzshik vonzshik modified the milestones: 9.0.0, 10.0.0 Oct 21, 2024
@NinoFloris NinoFloris force-pushed the output-parameter-handling branch from 42bc515 to 49abffe Compare October 29, 2025 23:40
Including support for generic parameters
Fixes #2252

# Conflicts:
#	src/Npgsql/NpgsqlDataReader.cs
@NinoFloris NinoFloris force-pushed the output-parameter-handling branch from 49abffe to c883e1b Compare November 5, 2025 18:54
var isSequential = _isSequential;
var currentPosition = Buffer.ReadPosition;
State = ReaderState.InResult;
_isSequential = false;
Copy link
Copy Markdown
Member Author

@NinoFloris NinoFloris Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To support reading generically we must allow the parameters to be read out of order to also support the two pass matching we do.

This is what originally led me down the road to an incorrect re-implementation.

@NinoFloris NinoFloris requested a review from vonzshik November 5, 2025 19:01
break;

// This set will also contain -1, but that's not a valid index so we can ignore it is included.
var matchedParameters = new HashSet<int>(parameterIndices);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could leave the hashset out on low fieldcount as well, just relying on simd indexof on the array.

@NinoFloris NinoFloris force-pushed the output-parameter-handling branch from 6140f56 to 55d17f4 Compare November 6, 2025 00:47
@NinoFloris NinoFloris merged commit ea5a2e1 into main Nov 10, 2025
18 checks passed
@NinoFloris NinoFloris deleted the output-parameter-handling branch November 10, 2025 13:01
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.

Investigate exact expected output parameter behavior

2 participants

X Tutup