NpgsqlCommand.DeriveParametersForFunction
See original GitHub issueI’m trying to integrate Npgsql to EntLib here https://github.com/Chavoshi/EnterpriseLibrary.NetCore/pull/27 and EntLib tries to match the number of parameter provided by the user with the number of the parameters detected on the database.
Looks like the query used at NpgsqlCommand.DeriveParametersForFunction
is not returning good results for functions that RETURNS SETOF table
.
The code is creating one output parameter for each column on the table due to the following code:
if (names != null && i < names.Length)
param.ParameterName = names[i];
else
param.ParameterName = "parameter" + (i + 1);
Example function:
CREATE OR REPLACE FUNCTION public.obtercamera(
pcameraid integer)
RETURNS SETOF camera
LANGUAGE 'plpgsql'
COST 100
VOLATILE
ROWS 1000
AS $BODY$
BEGIN
RETURN QUERY
SELECT CameraId, CameraUrl, Ativo, Criacao, Atualizacao
FROM Camera
WHERE CameraId = pCameraId OR pCameraId IS NULL;
END
$BODY$;
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Cannot derive function parameters for functions returning ...
DeriveParameters (NpgsqlCommand command) for a function which returns a TABLE result causes a NotImplementedException.
Read more >Class NpgsqlCommandBuilder
DeriveParameters (NpgsqlCommand). This method is responsible to derive the command parameter list with values obtained from function definition.
Read more >Npgsql failing on CommandBuilder DeriveParameters
The basic problem is that the interface to the PostgreSQL stored function can only use DbTypes specified by the NpgsqlDbType enumeration. The ...
Read more >DeriveParameters - Oracle Database
This method queries for the parameters of a stored procedure or function, represented by a specified OracleCommand , and populates the OracleParameterCollection ...
Read more >DB2Command.DeriveParameters Method
Retrieves parameter information for the command that is specified in the current DB2Command object (this) and populates the Parameters collection.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Got it. Since DAAB is no longer under active development I think the way I managed this behavior to work both ways in DAAB adapter is the best approach.
Nevertheless, IMHO, I don’t think the way Npgsql does it today is semantically consistent. If in the future PostgreSQL starts to support
IN
,OUT
andRETURNS SETOF record
(likeit would became confusing.obtercamera2
)– Edit:
obtercamera2
signature works.Ok, thank you.
So what I meant to say was that the following 3 function signatures are functionally equivalent in PostgreSQL and Npgsql:
Edit: edited demo signatures after thinking twice what the correct signature would have to look like.
All 3 signatures should (I haven’t actually tested it today) return the same result set in PostgreSQL and derive the same one IN and
45 OUT parameters in Npgsql.I understand that this isn’t what the Entlib DAAB is expecting but that’s how it is currently implemented.
Changing this would certainly need a broader discussion as it is a change that will break some peoples’ code. Especially given the fact that Entlib is no longer under active development.
From a purity point of view I’d support the argument that
obtercamera1
andobtercamera3
can bee seen as different fromobtercamera2
from the frontends perspective and shouldn’t derive any OUT parameters.cc: @roji @austindrenski @YohDeadfall