Skip to content

Commit

Permalink
Ignore parameters with ParameterDirection.ReturnValue (#5796)
Browse files Browse the repository at this point in the history
(cherry picked from commit 28d41bf)
  • Loading branch information
vonzshik authored and roji committed Sep 4, 2024
1 parent d03c487 commit a220780
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Npgsql/NpgsqlCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,9 @@ internal void ProcessRawQuery(SqlQueryParser? parser, bool standardConformingStr
if (EnableStoredProcedureCompatMode && parameter.Direction == ParameterDirection.Output)
continue;
if (parameter.Direction == ParameterDirection.ReturnValue)
continue;
if (isFirstParam)
isFirstParam = false;
else
Expand Down
19 changes: 19 additions & 0 deletions test/Npgsql.Tests/FunctionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ public async Task Too_many_output_params()
Assert.That(command.Parameters["c"].Value, Is.EqualTo(-1));
}

[Test, IssueLink("https://github.com/npgsql/npgsql/issues/5793")]
public async Task ReturnValue_parameter_ignored()
{
await using var conn = await OpenConnectionAsync();
var funcName = await GetTempFunctionName(conn);
await conn.ExecuteNonQueryAsync(@$"CREATE FUNCTION {funcName}() RETURNS integer AS 'SELECT 8;' LANGUAGE 'sql'");
await using var cmd = new NpgsqlCommand(funcName, conn) { CommandType = CommandType.StoredProcedure };
var param = new NpgsqlParameter
{
ParameterName = "@ReturnValue",
NpgsqlDbType = NpgsqlDbType.Integer,
Direction = ParameterDirection.ReturnValue,
Value = 0
};
cmd.Parameters.Add(param);
Assert.That(cmd.ExecuteScalar(), Is.EqualTo(8));
Assert.That(param.Value, Is.EqualTo(0));
}

[Test]
public async Task CommandBehavior_SchemaOnly_support_function_call()
{
Expand Down

0 comments on commit a220780

Please sign in to comment.