Bug #92367 MySqlDataReader.GetDateTime and GetValue return inconsistent values
Description:
When a TIMESTAMP column value is retrieved from MySQL, it's returned by Connector/NET as a System.DateTime object. The DateTime.Kind property of the returned object is different depending on whether it's retrieved by MySqlDataReader.GetDateTime() or MySqlDataReader.GetValue().
I would expect the DateTime.Kind property to be the same no matter how the value is retrieved from the reader. Secondly, based on bug #66964, I would expect the DateTime.Kind to be DateTimeKind.Local, so that the time can be intepreted correctly; having it set to Utc is wrong.
How to repeat:
Use a MySQL Server with a non-UTC time zone. (E.g., @@time_zone is SYSTEM and the server is running in PDT.)
Create a table with the following schema:
CREATE TABLE DateTimeTest (
RecordId INT NOT NULL PRIMARY KEY,
ModifiedDate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
Then execute the following C# code:
using (var connection = new MySqlConnection("..."))
{
connection.Open();
using (var cmd = new MySqlCommand("insert ignore into DateTimeTest(RecordId) VALUES(1);", connection))
cmd.ExecuteNonQuery();
using (var cmd = new MySqlCommand("select ModifiedDate from DateTimeTest;", connection))
using (var reader = cmd.ExecuteReader())
{
reader.Read();
// prints Local
Console.WriteLine(reader.GetDateTime(0).Kind);
// prints Utc
Console.WriteLine(((DateTime) reader.GetValue(0)).Kind);
// prints Utc
Console.WriteLine(reader.GetMySqlDateTime(0).GetDateTime().Kind);
}
}
Suggested fix:
Return local dates with DateTimeKind.Local no matter how they are retrieved from MySqlDataReader.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.040 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.