Bug #55644 Value was either too large or too small for a Double
Submitted: 30 Jul 2010 6:18 Modified: 12 Aug 2010 16:38
Reporter: Bogdan Degtyariov Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:6.2.3 OS:Any
Assigned to: Vladislav Vaintroub CPU Architecture:Any
Tags: double

[30 Jul 2010 6:18] Bogdan Degtyariov
Description:
Trying to read Double.MinVlue from a DOUBLE column in MySQL table throws the following exception:

System.OverflowException : Value was either too large or too small for a Double.

--OverflowException
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
at MySql.Data.Types.MySqlDouble.MySql.Data.Types.IMySqlValue.ReadValue(MySqlPacket packet, Int64 length, Boolean nullVal)
at MySql.Data.MySqlClient.NativeDriver.ReadColumnValue(Int32 index, MySqlField field, IMySqlValue valObject)
at MySql.Data.MySqlClient.ResultSet.ReadColumnData(Boolean outputParms)
at MySql.Data.MySqlClient.ResultSet.NextRow(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlDataReader.Read()

How to repeat:
private void btn_min_dbl_Click(object sender, EventArgs e)
{
    MySqlConnection con = new MySqlConnection();
    try
    {
        con.ConnectionString = "server=localhost;database=test;" +
                               "user id=**********;Password=*********;";
        con.Open();

        MySqlCommand cmd = new MySqlCommand();
        cmd.Connection = con;

        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "drop table if exists cs_double_min";
        cmd.ExecuteNonQuery();

        cmd.CommandText = "create table cs_double_min (id int auto_increment primary key, dbl double);";
        cmd.ExecuteNonQuery();

        cmd.CommandText = "insert into cs_double_min (id, dbl) values " +
                          "(1, ?param1);";
        cmd.Parameters.Add(new MySqlParameter("?param1", MySqlDbType.Double));
        cmd.Parameters["?param1"].Value = Double.MinValue;
        cmd.ExecuteNonQuery();

        cmd.CommandText = "SELECT * FROM cs_double_min;";
        MySqlDataReader dr = cmd.ExecuteReader();

        while (dr.Read())
            MessageBox.Show("ID: " + dr[0].ToString() + " DBL: " + dr[1].ToString() );

    }
    catch (Exception ex)
    {
        string error = ex.Message.ToString();
        error += ex.StackTrace;
        MessageBox.Show(error);
    }
}
[3 Aug 2010 15:56] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/114949

830 Vladislav Vaintroub	2010-08-03
      Bug#55644 : catch OverflowException when parsing double values returned by server,
      convert such values to double.minValue or double.maxValue dependent on sign.
[3 Aug 2010 16:06] Vladislav Vaintroub
fixed in 6.0.7, 6.1.5, 6.2.4, 6.3.4
[10 Aug 2010 10:25] Bogdan Degtyariov
Reading data from server should be as (MySqlDouble.cs:104):

     string s = packet.ReadString(length); // not just packet.ReadString();
     double d;
     try
     {
         d =  Double.Parse(s, CultureInfo.InvariantCulture);
     }
     catch (OverflowException)
...

Otherwise the string for parsing contains some stuff that causes parsing errors.
[10 Aug 2010 10:33] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/115388

832 Vladislav Vaintroub	2010-08-10
      post-push fix for Bug#55644 
      (length parameter in ReadString was lost the original push)
[12 Aug 2010 16:38] Tony Bedford
An entry has been added to the 6.0.7, 6.1.5, 6.2.4, 6.3.4 changelog:

Attempting to read Double.MinValue from a DOUBLE column in MySQL table generated the following exception:

System.OverflowException : Value was either too large or too small for a Double.

--OverflowException
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo
numfmt)
at MySql.Data.Types.MySqlDouble.MySql.Data.Types.IMySqlValue.ReadValue(MySqlPacket
packet, Int64 length, Boolean nullVal)
at MySql.Data.MySqlClient.NativeDriver.ReadColumnValue(Int32 index, MySqlField field,
IMySqlValue valObject)
at MySql.Data.MySqlClient.ResultSet.ReadColumnData(Boolean outputParms)
at MySql.Data.MySqlClient.ResultSet.NextRow(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlDataReader.Read()