Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid date can't be retrieved #529

Closed
bgrainger opened this issue Jul 6, 2018 · 1 comment
Closed

Invalid date can't be retrieved #529

bgrainger opened this issue Jul 6, 2018 · 1 comment
Assignees
Labels

Comments

@bgrainger
Copy link
Member

bgrainger commented Jul 6, 2018

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.

@bgrainger bgrainger added the bug label Jul 6, 2018
@bgrainger bgrainger self-assigned this Jul 6, 2018
@bgrainger
Copy link
Member Author

bgrainger commented Jul 6, 2018

Fixed in 0.42.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant