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

SQLite Driver don't encode QDateTime as ISO 8601

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • None
    • 5.9.0 Beta 2
    • SQL Support
    • None
    • 0679b96338b0803a3c9aced772396470bcf7e1e6

    Description

      Actually qtbase/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp has this code

      bool QSQLiteATResult::exec()
      {
      ...
                      case QVariant::DateTime: {
                          const QDateTime dateTime = value.toDateTime();
                          const QString str = dateTime.toString(QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz"));
                          res = sqlite3_bind_text16(d->stmt, i + 1, str.utf16(),
                                                    str.size() * sizeof(ushort), SQLITE_TRANSIENT);
                          break;
                      }
      

      But SQLite supports ISO 8601 https://sqlite.org/lang_datefunc.html, thus it would be more judicious to use

      dateTime.toString(Qt::ISODate)

      so as to keep the timezone. This code has an issue since QVariant::toDateTime() set the timezone to local time when we read back the date time. An UTC date time is thus incorrectly restored as a local time.

      See also QTBUG-26842

      Attachments

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

        Activity

          People

            Eddy Edward Welbourne
            fabricesalvaire fabrice salvaire
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes