You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This occurs with any schema. No need to create schema for reproducing.
Error is reported from Postgres server during parsing :p6 and before tables are accessed. I verified it by specifying standard postgres database as database name.
I updated issue and added ConnectionString() method.
Thanks for reporting @kobruleht, I can indeed reproduce this.
@glenebob, I think this is in your area of expertise... I've made a commit with a repro test: roji@b1a0378. Running it clearly shows that the string :p6 gets sent to the backend instead of getting replaced in AppendCommandReplacingParameterValues. Do you think you can take a look?
@roji my updated testcase contains 2 lines of sql to reproduce the issue. You can replace big sql in your commit with those 2 lines. It looke like AppendCommandReplacingParameterValues does not work properly if sql string contains '' which represent single quote.
In earlier versions of npgsql it worked OK.
@kobruleht , can you confirm if the empty string is still an issue? It was supposed to be fixed by now. I'm closing this issue now. If you still find problems with it, let us know.
proc:
CREATE OR REPLACE FUNCTION pr_getcustomeramount(IN pcountry character varying, OUT pcustomercount integer)
RETURNS integer AS $BODY$
BEGIN
SELECT COUNT(*) INTO pCustomerCount FROM Customers WHERE Country = pCountry;
END; $BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION pr_getcustomeramount(character varying)
OWNER TO postgres;
I'll see if I have time later today whether I can repro it in a unit test with the latest trunk code of npgsql. I can reproduce it on the released 2.2.1 assembly (.net 4.0 build)
It would be good with a unit test that shows the problem. I don't know how llblgen calls Npgsql. For example, is command type set to stored procedure or text.
Sorry, should have given that info. It creates a DbCommand using the factory and sets the commandtype to StoredProcedure. Input parameters only calls work fine, output parameters don't. I'll write a test which uses native commands to illustrate the problem.
When working with parameter in a NpgsqlCommand whose commandtype is StoredProcedure, you don't need to specify them in the CommandText. You just need to add the parameters as usual in the Parameters collection and let Npgsql take care of them for you.
In the case of output parameters, Postgresql return them as a resultset after the function is executed. Them, Npgsql will map them to any output parameter specified in your Parameters collection. If you add the output parameter marker in the commandtext, Npgsql will ignore it when calling the function (because it is output parameter) and then you get the error.
In the case of inputparameters, Npgsql will use them when calling the function. That's why you don't get errors when using input parameters only.
In order to be consistent and don't have this problem again, I'd suggest you to not add any parameter markers at all in your commandtext.
Check here a test we have about output parameter in our testsuite: (you can find a lot of other output parameters usage in our testsuite)
[Test]publicvoidTestBug1006158OutputParameters(){conststringcreateFunction=@"CREATE OR REPLACE FUNCTION more_params(OUT a integer, OUT b boolean) AS $BODY$DECLARE BEGIN a := 3; b := true; END;$BODY$ LANGUAGE 'plpgsql' VOLATILE;";varcommand=newNpgsqlCommand(createFunction,Conn);command.ExecuteNonQuery();command=newNpgsqlCommand("more_params",Conn);command.CommandType=CommandType.StoredProcedure;command.Parameters.Add(newNpgsqlParameter("a",DbType.Int32));command.Parameters[0].Direction=ParameterDirection.Output;command.Parameters.Add(newNpgsqlParameter("b",DbType.Boolean));command.Parameters[1].Direction=ParameterDirection.Output;varresult=command.ExecuteScalar();Assert.AreEqual(3,command.Parameters[0].Value);Assert.AreEqual(true,command.Parameters[1].Value);}
Note that only the name is specified in the commandtext and output parameters are added to the Parameters collection and have their value populated correctly.
Ok that helps :) I'll strip out generating the output proc names and leave the input proc names in, as I do recall they had to be there at some point in old(er) versions of npgsql? (removing all parameters from the header then would break code for ppl who still use older npgsql versions, but I don't have exact info on this)
(edit) omitting the output parameters works indeed. (on 2.2.1)
Ok that helps :) I'll strip out generating the output proc names and leave the input proc names in, as I do recall they had to be there at some point in old(er) versions of npgsql? (removing all parameters from the header then would break code for ppl who still use older npgsql versions, but I don't have exact info on this)
Yeah. If I recall correctly, only very very old Npgsql versions would need the parameter markers when calling functions, so you are right to have them there. I think that for 2.0.x and above you can omit them without fear.
(edit) omitting the output parameters works indeed. (on 2.2.1)
Excellent!
Please, let us know if you find any other problem, Frans!
I'm a big fan of your work and I'm glad to know Npgsql is being helpful to bring support of your tool to Postgresql!
:) Thanks Francisco! Yes stripping everything off (the brackets and all parameter markers) works fine, which makes it easy to fix this. If v2.x.y supports this, it's fine by me, older versions are too old anyway. So consider this solved! :)
:) Thanks Francisco! Yes stripping everything off (the brackets and all parameter markers) works fine, which makes it easy to fix this. If v2.x.y supports this, it's fine by me, older versions are too old anyway. So consider this solved! :)
Activity
roji commentedon Jul 26, 2014
Should be resolved for 2.2...
roji commentedon Jul 26, 2014
@kobruleht, any way you could send SQL to create the schema for this query, to help with reproducing?
kobruleht commentedon Jul 26, 2014
This occurs with any schema. No need to create schema for reproducing.
Error is reported from Postgres server during parsing :p6 and before tables are accessed. I verified it by specifying standard postgres database as database name.
I updated issue and added ConnectionString() method.
kobruleht commentedon Jul 26, 2014
@roji I updated testcase so it does not reference any tables.
Repro unit test for npgsql#296
roji commentedon Jul 26, 2014
Thanks for reporting @kobruleht, I can indeed reproduce this.
@glenebob, I think this is in your area of expertise... I've made a commit with a repro test: roji@b1a0378. Running it clearly shows that the string :p6 gets sent to the backend instead of getting replaced in AppendCommandReplacingParameterValues. Do you think you can take a look?
kobruleht commentedon Jul 26, 2014
@roji my updated testcase contains 2 lines of sql to reproduce the issue. You can replace big sql in your commit with those 2 lines. It looke like AppendCommandReplacingParameterValues does not work properly if sql string contains '' which represent single quote.
In earlier versions of npgsql it worked OK.
franciscojunior commentedon Jul 29, 2014
Hi, @glenebob ! Were you able to have a look at this issue? It is a pretty important regression.
Thanks in advance!
glenebob commentedon Jul 29, 2014
Ah, no, I missed it (was out on vacation all last week). I'll try to look
at it in the next couple days.
-Glen
On Tue, Jul 29, 2014 at 9:55 AM, Francisco Figueiredo Jr. <
[email protected]> wrote:
franciscojunior commentedon Jul 29, 2014
Thank you very much, Glen!
franciscojunior commentedon Aug 1, 2014
I think this problem was also reported in #240 .
glenebob commentedon Aug 2, 2014
@roji, I took your repro test and simplified the heck out of it :) I should have this fixed shortly.
-Glen
9 remaining items
Bugs #249 and #296 Unit Test Improvements
kobruleht commentedon Aug 13, 2014
Ca we add empty string
select ''
to unit test. It also stopped parameter parsing.
franciscojunior commentedon Aug 17, 2014
This is fixed in Npgsql 2.2.0-rc1. Please, give it a try and let us know if you find any other problem.
franciscojunior commentedon Aug 17, 2014
@kobruleht , can you confirm if the empty string is still an issue? It was supposed to be fixed by now. I'm closing this issue now. If you still find problems with it, let us know.
FransBouma commentedon Oct 23, 2014
Still fails in 2.2.1 with an output parameter.
proc:
$BODY$
$BODY$
CREATE OR REPLACE FUNCTION pr_getcustomeramount(IN pcountry character varying, OUT pcustomercount integer)
RETURNS integer AS
BEGIN
SELECT COUNT(*) INTO pCustomerCount FROM Customers WHERE Country = pCountry;
END;
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION pr_getcustomeramount(character varying)
OWNER TO postgres;
(on northwind DB on postgres).
Call: "Northwind"."public"."pr_getcustomeramount"(:pcountry, :pcustomercount)"
Fails with the same error at ':'. See for more info:
http://www.llblgen.com/tinyforum/GotoMessage.aspx?MessageID=130522&ThreadID=22680
I'll see if I have time later today whether I can repro it in a unit test with the latest trunk code of npgsql. I can reproduce it on the released 2.2.1 assembly (.net 4.0 build)
Emill commentedon Oct 23, 2014
It would be good with a unit test that shows the problem. I don't know how llblgen calls Npgsql. For example, is command type set to stored procedure or text.
FransBouma commentedon Oct 23, 2014
Sorry, should have given that info. It creates a DbCommand using the factory and sets the commandtype to StoredProcedure. Input parameters only calls work fine, output parameters don't. I'll write a test which uses native commands to illustrate the problem.
franciscojunior commentedon Oct 23, 2014
Hi, @FransBouma !
When working with parameter in a NpgsqlCommand whose commandtype is StoredProcedure, you don't need to specify them in the CommandText. You just need to add the parameters as usual in the Parameters collection and let Npgsql take care of them for you.
In the case of output parameters, Postgresql return them as a resultset after the function is executed. Them, Npgsql will map them to any output parameter specified in your Parameters collection. If you add the output parameter marker in the commandtext, Npgsql will ignore it when calling the function (because it is output parameter) and then you get the error.
In the case of inputparameters, Npgsql will use them when calling the function. That's why you don't get errors when using input parameters only.
In order to be consistent and don't have this problem again, I'd suggest you to not add any parameter markers at all in your commandtext.
Check here a test we have about output parameter in our testsuite: (you can find a lot of other output parameters usage in our testsuite)
Note that only the name is specified in the commandtext and output parameters are added to the Parameters collection and have their value populated correctly.
I hope it helps.
FransBouma commentedon Oct 23, 2014
Ok that helps :) I'll strip out generating the output proc names and leave the input proc names in, as I do recall they had to be there at some point in old(er) versions of npgsql? (removing all parameters from the header then would break code for ppl who still use older npgsql versions, but I don't have exact info on this)
(edit) omitting the output parameters works indeed. (on 2.2.1)
Emill commentedon Oct 23, 2014
Well, according to the documentation at http://msdn.microsoft.com/en-us/library/system.data.common.dbcommand.commandtype(v=vs.110).aspx, it states that the CommandText should simply contain the name of the stored procedure...
franciscojunior commentedon Oct 23, 2014
Yeah. If I recall correctly, only very very old Npgsql versions would need the parameter markers when calling functions, so you are right to have them there. I think that for 2.0.x and above you can omit them without fear.
Excellent!
Please, let us know if you find any other problem, Frans!
I'm a big fan of your work and I'm glad to know Npgsql is being helpful to bring support of your tool to Postgresql!
FransBouma commentedon Oct 23, 2014
:) Thanks Francisco! Yes stripping everything off (the brackets and all parameter markers) works fine, which makes it easy to fix this. If v2.x.y supports this, it's fine by me, older versions are too old anyway. So consider this solved! :)
franciscojunior commentedon Oct 23, 2014
Awesome! I'm glad to hear that. :)