Bug #39294 Reading negative time value greater than -01:00:00 return positive value
Submitted: 7 Sep 2008 12:59 Modified: 15 Sep 2008 15:00
Reporter: Michal Minárik Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:5.2.3 OS:Windows (Vista 32-bit)
Assigned to: CPU Architecture:Any
Tags: time negative select

[7 Sep 2008 12:59] Michal Minárik
Description:
Reading negative time value greater than -01:00:00 return positive value (absolute value of the original time value).

How to repeat:
-- SQL

DROP TABLE IF EXISTS test;

CREATE TABLE `test` (
`id` int(11) NOT NULL auto_increment,
`time` time NOT NULL default '00:00:00',
PRIMARY KEY  (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

INSERT INTO `my_db`.`test` (`time`) VALUES ('-00:10:00');

-- C#

MySqlCommand command = new MySqlCommand();
command.Connection = conn;
command.CommandType = CommandType.Text;
command.CommandText = "SELECT time FROM test";
using (MySqlDataReader reader = command.ExecuteReader())
{
  reader.Read();
  TimeSpan time = reader.GetTimeSpan(reader.GetOrdinal("time"));
  // time is 00:10:00
}

Suggested fix:
The definition of MySqlTime.ParseMySql(...) could be:

private void ParseMySql(string s, bool is41)
{
  string[] parts = s.Split(':');
  int hours = Int32.Parse(parts[0]);
  int mins = Int32.Parse(parts[1]);
  int secs = Int32.Parse(parts[2]);

  if (hours < 0 || parts[0].StartsWith("-"))
  {
    mins *= -1;
    secs *= -1;
  }

  int days = hours / 24;
  hours = hours - (days * 24);
  mValue = new TimeSpan(days, hours, mins, secs, 0);
  isNull = false;
}
[8 Sep 2008 6:22] Tonci Grgin
Hi Michal and thanks for your report.

Truly there is a bug and it can be seen just by looking into code. I suppose fix for Bug#25912 was incomplete.
[8 Sep 2008 18: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/53539
[8 Sep 2008 18:33] Reggie Burnett
fixed in 5.2.4
[15 Sep 2008 14:59] Tony Bedford
Added an entry to the 5.2.4 changelog:

Reading a negative time value greater than -01:00:00 returned the absolute value of the original time value.