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

QtSql/pgSql cannot read datetime (timestamp with time zone)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Not Evaluated Not Evaluated
    • None
    • 6.8.0
    • SQL Support
    • None
    • macOS
    • 8ebf6dcd12937e9f74f5a6379338acc4bcd7efd6

      I have my application that reads from the DB. It was always working up to 6.8.0.

      When it reads a datetime from my postgresql DB, it returns an invalid QDateTime.

      I was able to recreate it with the attached program (of course you need to adapt the connection to your db cluster.

      It seems to be on columns that are defined as "timestamp with time zone". Simple timestamps work just fine.

       

      This is a fix that worked for me:

      diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp
      index 7b9521f..f802a2e 100644
      --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp
      +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp
      @@ -652,7 +652,7 @@ QVariant QPSQLResult::data(int i)
               return QVariant(QTime::fromString(QString::fromLatin1(val), Qt::ISODate));
           case QMetaType::QDateTime: {
               QString tzString(QString::fromLatin1(val));
      -        if (!tzString.endsWith(u'Z'))
      +        if (ptype != QTIMESTAMPTZOID && !tzString.endsWith(u'Z'))
                   tzString.append(u'Z');       // make UTC
               return QVariant(QDateTime::fromString(tzString, Qt::ISODate));
           }
       

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

            chehrlic Christian Ehrlicher
            thierryb Thierry Bastian
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes