X Tutup
Skip to content

Impossible to insert a Double.NaN value #217

@Tradioyes

Description

@Tradioyes

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");
        }
    }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    X Tutup