Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.8.2
-
None
-
219e9fe7a (dev), 3b175fbec (6.9), 1b11ab412 (6.8)
Description
When writing a QDateTime in a DATETIME sql field (in a MySQL datatbase) QMYSQLDriver::formatValue returns a string like that
r = u'\'' + dt.date().toString(Qt::ISODate) + u'T' + dt.time().toString(Qt::ISODate) + u'\'';
and QMYSQLResult::data reads it like that
return QDateTime(date, time, QTimeZone::UTC);
Assuming it is always stored in UTC.
However, if a localTime is passed to the formatValue method (for instance QDateTime(2025-03-25 11:14:25.000 CET Qt::LocalTime)) it is stored in this format "2025-03-25T11:14:25". But when it is retrived with a SELECT, it is returned as QDateTime(2025-03-25 11:14:25.000 UTC Qt::UTC)
Edit: I know that in the docs https://doc.qt.io/qt-6/sql-driver.html#timestamp-support it says it is normal, but since MySQL does not store any timezone information, the retrieved data should not be assumed to be UTC
Attachments
For Gerrit Dashboard: QTBUG-135135 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
635278,6 | SQL/MySQL: use utc datetime in formatValue() | dev | qt/qtbase | Status: MERGED | +2 | 0 |
636150,2 | SQL/MySQL: use utc datetime in formatValue() | 6.9 | qt/qtbase | Status: MERGED | +2 | 0 |
636365,2 | SQL/MySQL: use utc datetime in formatValue() | 6.8 | qt/qtbase | Status: MERGED | +2 | 0 |