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
OffsetDateTime parsing is broken for MySQL datetime column #1984
Comments
@smootoo is the expert here, but AFAIK this code is not meant to work with MySQL DATETIME, such as 2016-08-11 20:24:18.0, as it doesn't have a required timezone offset. If that is the case, then this issue should be closed as not a bug. |
@sjbog the data type that corresponds to MySQL |
@hvesalai the bug I see - is an assumption that OffsetDateTime column is ISO 8601 string
Another solution would be to remove |
@sjbog The solution taken here is to use a VARCHAR column for OffsetDateTime (see https://github.com/slick/slick/blob/v3.3.0/slick/src/main/scala/slick/jdbc/JdbcTypesComponent.scala#L319). In your case the database has not been created by Slick and that is what is causing the mismatch. So the column would be in ISO 8601 if the database schema was of the expected type and the values had been written by slick. |
The missing documentation on this feature is here: https://github.com/slick/slick/pull/1985/files |
In my experience, that is often the case for production systems: Slick doesn't provide a good story for database migrations. So, you're left with using another tool like Flyway or Liquibase to create the tables. Given the 2038 limit for It would be great if Slick had a recommended way of supporting that scenario. |
Maybe some more solutions:
...
|
I'm confused. Is the issue specific to OffsetDateTime or does it apply to LocalDateTime? |
According to the source code it applies to Instant and LocalDateTime. |
DESCRIPTION:
MySQL
DATETIME
column can't be parsed as ISO 8601DateTimeFormatter.ISO_OFFSET_DATE_TIME
https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_get-format
https://stackoverflow.com/a/28323923
https://github.com/slick/slick/blob/v3.3.0/slick/src/main/scala/slick/jdbc/JdbcTypesComponent.scala#L327
STEPS TO REPRODUCE
MySQL v5.7, Slick v3.3.0
Table
RESULT
MySQL returns datetime values in ISO 9075. For example
2016-08-11 20:24:18.0
Possible solutions
resultSet.getTimestamp
as parsing base instead of getString.DATE_FORMAT
in queriesThe text was updated successfully, but these errors were encountered: