Bug #100218 | TIME(n) column deserializes milliseconds incorrectly with prepared command | ||
---|---|---|---|
Submitted: | 14 Jul 2020 15:00 | Modified: | 17 Jul 2020 19:55 |
Reporter: | Bradley Grainger (OCA) | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / NET | Severity: | S3 (Non-critical) |
Version: | 8.0.21 | OS: | Windows (10) |
Assigned to: | CPU Architecture: | Any |
[14 Jul 2020 15:00]
Bradley Grainger
[14 Jul 2020 15:02]
Bradley Grainger
Here's a variant of the bug for TIME(6) that deserializes microseconds incorrectly: using (var connection = new MySqlConnection("...;IgnorePrepare=false")) { connection.Open(); using (var command = new MySqlCommand(@" DROP TABLE IF EXISTS test_time; CREATE TABLE test_time(data TIME(6) NOT NULL); ", connection)) command.ExecuteNonQuery(); using (var command = new MySqlCommand(@"INSERT INTO test_time VALUES(@data);", connection)) { // prints: 1.02:03:04.0005600 var ts = new TimeSpan(1, 2, 3, 4) + TimeSpan.FromTicks(5600); Console.WriteLine(ts); command.Parameters.AddWithValue("@data", ts); command.ExecuteNonQuery(); } using (var command = new MySqlCommand(@"SELECT data FROM test_time;", connection)) { // *** this causes the bug *** command.Prepare(); var result = (TimeSpan)command.ExecuteScalar(); // prints 1.02:03:04.0560000, expected 1.02:03:04.0005600 Console.WriteLine(result); } }
[15 Jul 2020 8:18]
MySQL Verification Team
Hello Bradley, Thank you for the report and test case. Verified as described. regards, Umesh
[17 Jul 2020 19:55]
Christine Cole
Posted by developer: Fixed as of the upcoming MySQL Connector/NET 8.0.22 release, and here's the proposed changelog entry from the documentation team: Microseconds were deserialized incorrectly when MySqlCommand.Prepare() was called for a statement that selects a TIME(n) column, resulting in a loss of trailing zeros in the returned result. Now, the MySqlTime class calculates ticks, rather than converting the microseconds to a string. Thank you for the bug report.