Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-135135

QMySqlDriver QDateTime is not consistant between read/write

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.8.4, 6.9.1, 6.10.0 FF
    • 6.8.2
    • SQL Support
    • 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

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            chehrlic Christian Ehrlicher
            romain.donze Romain Donzé
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes