Skip to content

Invalid date can't be retrieved #529

Description

@bgrainger

When ALLOW_INVALID_DATES is enabled on the MySQL Server, "invalid" dates such as 2018-02-31 may be stored in a DATE column.

Calling MySqlDataReader.GetValue for a column containing an invalid date will throw the following exception:

ArgumentOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime.
  at System.DateTime.DateToTicks(Int32 year, Int32 month, Int32 day)
   at System.DateTime..ctor(Int32 year, Int32 month, Int32 day, Int32 hour, Int32 minute, Int32 second, Int32 millisecond, DateTimeKind kind)
   at MySqlConnector.Core.Row.ParseDateTime(ReadOnlySpan`1 value)
   at MySqlConnector.Core.Row.GetValue(Int32 ordinal)
   at MySql.Data.MySqlClient.MySqlDataReader.GetValue(Int32 ordinal)

In Connector/NET, if you enable AllowZeroDateTime=true in the connection string, all DATE columns are returned as MySqlDateTime objects, which can represent this unrepresentable DateTime. In MySqlConnector, the DateTime constructor is always used (even with AllowZeroDateTime=true) which throws this exception.

This is possibly the cause of #527.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions