-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Fix bug where a non-sproc command comes before a sproc command #29680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,12 +91,14 @@ protected override void Consume(RelationalDataReader reader) | |
var parameterCounter = 0; | ||
IReadOnlyModificationCommand command; | ||
|
||
for (commandIndex = 0; | ||
commandIndex < ResultSetMappings.Count; | ||
commandIndex++, parameterCounter += command.StoreStoredProcedure!.Parameters.Count) | ||
for (commandIndex = 0; commandIndex < ResultSetMappings.Count; commandIndex++, parameterCounter += ParameterCount(command)) | ||
{ | ||
command = ModificationCommands[commandIndex]; | ||
|
||
Check.DebugAssert( | ||
command.ColumnModifications.All(c => c.UseParameter), | ||
"This code assumes all column modifications involve a DbParameter (see counting above)"); | ||
|
||
if (!ResultSetMappings[commandIndex].HasFlag(ResultSetMapping.HasOutputParameters)) | ||
{ | ||
continue; | ||
|
@@ -210,12 +212,14 @@ protected override async Task ConsumeAsync( | |
var parameterCounter = 0; | ||
IReadOnlyModificationCommand command; | ||
|
||
for (commandIndex = 0; | ||
commandIndex < ResultSetMappings.Count; | ||
commandIndex++, parameterCounter += command.StoreStoredProcedure!.Parameters.Count) | ||
for (commandIndex = 0; commandIndex < ResultSetMappings.Count; commandIndex++, parameterCounter += ParameterCount(command)) | ||
{ | ||
command = ModificationCommands[commandIndex]; | ||
|
||
Check.DebugAssert( | ||
command.ColumnModifications.All(c => c.UseParameter), | ||
"This code assumes all column modifications involve a DbParameter (see counting above)"); | ||
|
||
if (!ResultSetMappings[commandIndex].HasFlag(ResultSetMapping.HasOutputParameters)) | ||
{ | ||
continue; | ||
|
@@ -477,6 +481,35 @@ await ThrowAggregateUpdateConcurrencyExceptionAsync( | |
return commandIndex - 1; | ||
} | ||
|
||
private static int ParameterCount(IReadOnlyModificationCommand command) | ||
{ | ||
// As a shortcut, if the command uses a stored procedure, return the number of parameters directly from it. | ||
if (command.StoreStoredProcedure is { } storedProcedure) | ||
{ | ||
return storedProcedure.Parameters.Count; | ||
} | ||
|
||
// Otherwise we need to count the total parameters used by all column modifications | ||
var parameterCount = 0; | ||
|
||
for (var i = 0; i < command.ColumnModifications.Count; i++) | ||
{ | ||
var columnModification = command.ColumnModifications[i]; | ||
|
||
if (columnModification.UseCurrentValueParameter) | ||
{ | ||
parameterCount++; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would also make sense to do this when building the modification command and expose the count for both types of commands though a single property There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I thought about this, and didn't do this mainly since we want to backport the fix to 7.0, and should avoid new public APIs. I can do this in a separate PR after this is merged. I'm not sure I'd eagerly calculate this though (during the building of the command) - it's currently only needed when output parameters are present, which is a rare sproc-only case. |
||
} | ||
|
||
if (columnModification.UseOriginalValueParameter) | ||
{ | ||
parameterCount++; | ||
} | ||
} | ||
|
||
return parameterCount; | ||
} | ||
|
||
private IReadOnlyList<IUpdateEntry> AggregateEntries(int endIndex, int commandCount) | ||
{ | ||
var entries = new List<IUpdateEntry>(); | ||
|
Uh oh!
There was an error while loading. Please reload this page.