Impossible to insert a Double.NaN value #217

Closed
Tradioyes opened this Issue Apr 17, 2014 · 4 comments

Projects

None yet

4 participants

@Tradioyes
Contributor

This is a regression from 2.0.13-beta1.
I tried to upgrade to 2.1.3 and Npgsql crashed when I try to insert a NaN value in a double precision field.
The error is:
Npgsql.NpgsqlException : ERROR: 42703: column "nan" does not exist

The first tests works, the second raises the error.

    [Test]
    public void HandleDoubleValueParameter()
    {
        ExecuteNonQuery(@"CREATE TABLE dataDouble (
                            field_double                  double precision
                            )");
        try
        {
            var command = new NpgsqlCommand("insert into dataDouble(field_double) values (:a)", Conn);
            command.Parameters.Add(new NpgsqlParameter("a", NpgsqlDbType.Double));
            command.Parameters[0].Value = 123.456;
            var query = command.CommandText;
            var rowsAdded = command.ExecuteNonQuery();
            Assert.AreEqual(1, rowsAdded);
        }
        finally
        {
            ExecuteNonQuery(@"DROP TABLE dataDouble");
        }
    }

    [Test]
    public void HandleDoubleNanValueParameter()
    {
        ExecuteNonQuery(@"CREATE TABLE dataDouble (
                            field_double                  double precision
                            )");

        try
        {
            var command = new NpgsqlCommand("insert into dataDouble(field_double) values (:a)", Conn);
            command.Parameters.Add(new NpgsqlParameter("a", NpgsqlDbType.Double));
            command.Parameters[0].Value = double.NaN;
            var query = command.CommandText;
            var rowsAdded = command.ExecuteNonQuery();
            Assert.AreEqual(1, rowsAdded);
        }
        finally
        {
            ExecuteNonQuery(@"DROP TABLE dataDouble");
        }
    }
@franciscojunior
Member

I'll check that. Thanks for your report!

@franciscojunior franciscojunior added the bug label Apr 17, 2014
@franciscojunior franciscojunior added this to the 2.2 milestone Apr 17, 2014
@franciscojunior
Member

Sorry for late reply.

Indeed this regression was caused by changes in the way we send the data to the server.

For while, a workaround is to use a prepared statement.

I'm working on a fix.

@franciscojunior franciscojunior added a commit to franciscojunior/Npgsql that referenced this issue Jun 16, 2014
@franciscojunior franciscojunior Fix #217 when handling NaN for float4 and float8 datatypes.
After commit 854862a Npgsql wasn't adding quotes around float4 and float8 values.
But according to documentation, NaN values need to be quoted.
a476491
@franciscojunior franciscojunior added a commit to franciscojunior/Npgsql that referenced this issue Jun 25, 2014
@franciscojunior franciscojunior Fix #217 when handling NaN for float4 and float8 datatypes.
After commit 854862a Npgsql wasn't adding quotes around float4 and float8 values.
But according to documentation, NaN values need to be quoted.
3cbec04
@franciscojunior franciscojunior added a commit to franciscojunior/Npgsql that referenced this issue Jul 12, 2014
@franciscojunior franciscojunior Fix #217 when handling NaN for float4 and float8 datatypes.
After commit 854862a Npgsql wasn't
adding quotes around float4 and float8 values.

But according to documentation, NaN values need to be quoted.

Separated handling of float4 and float8 conversion routines.
3f01e79
@roji
Member
roji commented Jul 30, 2014

@franciscojunior, this is one of the last issues for 2.2 Is it a duplicate of #257? Are you working on it or is @glenebob?

@franciscojunior
Member

@franciscojunior, this is one of the last issues for 2.2 Is it a duplicate of #257? Are you working on it or is @glenebob?

I asked @glenebob to have a look at it. He said he will look on this weekend.
#257 is the pull request with my fix for this issue.

@glenebob glenebob added a commit to glenebob/Npgsql2 that referenced this issue Aug 2, 2014
@glenebob glenebob Fix #217 double NaN regression #2
Add non-quoted and double quoted NaN ASCII string values.
Move QuoteASCIIString() from NpgsqlNativeTypeInfo to BasicNativeToBackendTypeConverter.
Add support in QuoteASCIIString() for predetermined quoted values.
Use QuoteASCIIString() in the two native float to backend float text converters.
6857b0c
@glenebob glenebob closed this in #257 Aug 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment