Skip to content

Add support to translate a database returned string to a requested System.DateTime #980

@lauxjpn

Description

@lauxjpn

Check out the following SQL:

SELECT `g`.`Nickname`, COALESCE((
    SELECT `t1`.`IssueDate`
    FROM `Tags` AS `t1`
    WHERE `t1`.`GearNickName` = `g`.`FullName`
    ORDER BY `t1`.`Id`
    LIMIT 1), '0001-01-01 00:00:00') AS `invalidTagIssueDate`
FROM `Gears` AS `g`
LEFT JOIN `Tags` AS `t` ON (`g`.`Nickname` = `t`.`GearNickName`) AND (`g`.`SquadId` = `t`.`GearSquadId`)
WHERE `t`.`IssueDate` > COALESCE((
    SELECT `t0`.`IssueDate`
    FROM `Tags` AS `t0`
    WHERE `t0`.`GearNickName` = `g`.`FullName`
    ORDER BY `t0`.`Id`
    LIMIT 1), '0001-01-01 00:00:00')

It should return the following result set, with invalidTagIssueDate being of type datetime:

+------------+----------------------------+
| Nickname   | invalidTagIssueDate        |
+------------+----------------------------+
| Cole Train | 0001-01-01 00:00:00.000000 |
| Baird      | 0001-01-01 00:00:00.000000 |
| Dom        | 0001-01-01 00:00:00.000000 |
| Paduk      | 0001-01-01 00:00:00.000000 |
| Marcus     | 0001-01-01 00:00:00.000000 |
+------------+----------------------------+
5 rows in set (0.00 sec)

However, MySQL does not recognize, that the '0001-01-01 00:00:00' string is a datetime literal and just returns it as a string:

+------------+---------------------+
| Nickname   | invalidTagIssueDate |
+------------+---------------------+
| Cole Train | 0001-01-01 00:00:00 |
| Baird      | 0001-01-01 00:00:00 |
| Dom        | 0001-01-01 00:00:00 |
| Paduk      | 0001-01-01 00:00:00 |
| Marcus     | 0001-01-01 00:00:00 |
+------------+---------------------+
5 rows in set (0.00 sec)

The result is, that when a System.DateTime is requested from the data reader, MySqlConnector throws.

It would therefore make sense, that MySqlConnector gracefully parses a string to a DateTime, if a DateTime is requested by the user, but a string returned by the database.

Otherwise, Pomelo would need to explicitly cast all datetime literals explicitly to datetime, which is probably fine for us.
But fixing this MySQL behavior in MySqlConnector would also solve the issue for non Pomelo users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions