Exception thrown reading negative time value

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
DwightFowler
Posts: 9
Joined: Wed 02 Apr 2008 03:14

Exception thrown reading negative time value

Post by DwightFowler » Thu 12 Jun 2008 20:29

Hi,
When I try and read a column that has a negative time value, CoreLabs throws an exception "Incorrect Format".
Steps to reproduce:
1) create a table

Code: Select all

CREATE TABLE `negativetimetest` (
`tst_id` int(11) NOT NULL AUTO_INCREMENT,
`start_date` datetime DEFAULT NULL,
`end_date` datetime DEFAULT NULL,
`time` time DEFAULT NULL,
PRIMARY KEY (`tst_id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
2) Insert data with a negative time value

Code: Select all

INSERT INTO negativetimetest (tst_id, start_date, end_date, time) VALUES ('20080611', '20080612', '2008-06-11', '-14:00:00');
3) Run the following code in visual studio:

Code: Select all

    private void button1_Click(object sender, EventArgs e)
    {
      MySqlConnection conn = new MySqlConnection();
      MySqlConnectionStringBuilder sb = new MySqlConnectionStringBuilder();
      sb.Database = "test";
      sb.Direct = true;
      sb.Host = "myhost";
      sb.Password = "mypassword";
      sb.Unicode = true;
      sb.UserId = "myuserid";

      conn.ConnectionString = sb.ConnectionString;
      conn.Open();
      if (conn.State != ConnectionState.Open)
        return;

      MySqlDataReader reader = null;
      try
      {
        MySqlCommand cmd = new MySqlCommand("select * from negativetimetest");
        cmd.Connection = conn;
        reader = cmd.ExecuteReader();
        while (reader.Read())
        {
          rtbResult.AppendText(string.Format("Current record: {0}\r\n", reader.CurrentRecord));
          rtbResult.AppendText(string.Format("tst_id ={0}, ", reader.GetInt32(0).ToString()));
          rtbResult.AppendText(string.Format("start_date ={0}, ", reader.GetDateTime(1)));
          rtbResult.AppendText(string.Format("end_date ={0}, ", reader.GetDateTime(2)));
          rtbResult.AppendText(string.Format("time ={0}\r\n", reader.GetTimeSpan(3)));
        } 
      }
      catch (Exception ex)
      {
        rtbResult.AppendText(string.Format("\r\nError: {0}\r\n{1}\r\n",ex.Message, ex.StackTrace));
      }
      finally
      {
        if (reader != null)
          reader.Close();
      }
      conn.Close();
    }
  }
Output:
Current record: 0
tst_id =20080611, start_date =6/12/2008 12:00:00 AM, end_date =6/11/2008 12:00:00 AM,
Error: IncorrectFormat
at CoreLab.MySql.bb.d(Byte[] A_0, Int32 A_1, Int32 A_2)
at CoreLab.MySql.MySqlDataReader.GetTimeSpan(Int32 i)
at NegativeTime.Form1.button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\DFowler\My Documents\Visual Studio 2005\Projects\NegativeTime\NegativeTime\Form1.cs:line 47

Alexey.mdr
Posts: 729
Joined: Thu 13 Dec 2007 10:24

Post by Alexey.mdr » Tue 17 Jun 2008 09:05

Hello,

This bug with negative timestamp has been already fixed in the newest build.
But we found another related issue.
If the negative timespan contains minutes it's not parsed correctly. The problem is fixed already.
Look forward to the next build.

Regards,
Alexey.

DwightFowler
Posts: 9
Joined: Wed 02 Apr 2008 03:14

Negative time stamp

Post by DwightFowler » Tue 17 Jun 2008 18:22

Alexy,

Thanks for the update. That's great news. We'll incorporate the fixes in our next release.


Dwight

Post Reply