Status changed to: Closed

Title: Parameter name and order of declaration
Bug Type: Software bug
Severity: Serious
Software Version: 0.7.1
Environment: Windows XP
PostgreSQL 8.0.4 on i686-pc-mingw32, compiled by GCC gcc.exe (GCC) 3.4.2 
(mingw-special)

Created By: [EMAIL PROTECTED]
Description: Hello,
 I have come accross a problem using parameters in a query.
Here is a code extract:

...
NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User 
Id=joe;Password=secret;Database=joedata;");
    conn.Open();
    
string
NpgsqlCommand command = new NpgsqlCommand("select * from tablea where column1 = 
:AA and column2 = :A", conn);
    
command.Parameters.Add(new NpgsqlParameter("A", DbType.Int32));
command.Parameters.Add(new NpgsqlParameter("AA", DbType.Int32));


command.Parameters[0].Value = 4;
command.Parameters[1].Value = 5;
    
command.ExecuteReader();
...

Declaring the parameter in this order ("A" then "AA") will raise the following 
exception :
System.IndexOutOfRangeException
Message: "Parameter :A not found in query."

Declaring them in the opposite order works without a glitch.

PS: here the relevant part of the stack trace for the exception:
at Npgsql.NpgsqlCommand.ReplaceParameterValue(String result, String 
parameterName, String paramVal)
at Npgsql.NpgsqlCommand.GetClearCommandText()
at Npgsql.NpgsqlCommand.GetCommandText()  
at Npgsql.NpgsqlQuery.WriteToStream(Stream outputStream, Encoding encoding)
at Npgsql.NpgsqlReadyState.Query(NpgsqlConnector context, NpgsqlCommand command)
at Npgsql.NpgsqlConnector.Query(NpgsqlCommand queryCommand)
at Npgsql.NpgsqlCommand.ExecuteCommand()
at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior cb)
at Npgsql.NpgsqlCommand.ExecuteReader()
at Npgsql.NpgsqlCommand.System.Data.IDbCommand.ExecuteReader()
at TestPgsql.TestPgsql.Main(String[] args)

Status: Closed


[EMAIL PROTECTED] : 11/02/2005
        
Hi ymh.

Would you mind to check if you are really using Npgsql 0.7.1? It is because we 
fixed this problem since 0.7beta6 with a new algorithm based on regexp.

Also, from your stack trace, GetClearCommandText is calling 
ReplaceParameterValue and this call was removed.

Another way to check if you are using 0.7.1 is enable logging, with 
                NpgsqlEventLog.Level = LogLevel.Debug;
                NpgsqlEventLog.LogName = "NpgsqlTests.LogFile";

and check if you see some string like that:
String written:

Which shows what Npgsql is writing to server.

Just one more thing: Please, use tracker at www.pgfoundry.org/projects/npgsql 
to report new bugs :)

Thanks in advance.

[EMAIL PROTECTED] : 11/03/2005
        Hello fxjrlists.

Indeed, thanks to your indications, I discovered that I was not using the 
version 0.7.1.0, but the 0.7.0.O (as read with ildasm), the one delivered with 
the installation of postgresql 8.0.4 for windows.

Everything was running fine once using the correct version.
 
Sorry for the inconvenience.

ymh

[EMAIL PROTECTED] : 11/04/2005
        
Hi Ymh.

No problem. It wasn't any inconvenience :)
I'm glad you got it working!

I think newer versions of Postgresql installer will come with latest Npgsql 
version.

Thank you for your feedback.


http://gborg.postgresql.org/project/npgsql/bugs/bugupdate.php?1455

_______________________________________________
Npgsql-hackers mailing list
Npgsql-hackers@gborg.postgresql.org
http://gborg.postgresql.org/mailman/listinfo/npgsql-hackers

Reply via email to