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

QSqlQuery Postgres and timestamp => QDateTime(Invalid)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P1: Critical
    • 6.8.1, 6.9.0 FF
    • 6.8.0
    • SQL Support
    • None
    • QT app running Windows 10, MSVC 2022
      Postgres-Server 16.04 on Debian Bokkwoorm
    • All
    • 00edd4776 (dev), 9e22cd089 (6.8), d6a7e51fa (dev), df1118b4e (6.8)

    Description

      Hi,

      During migration of a project from Qt 6.7.3 to 6.8 I stumbled over a wired invalid QDateTime variant. I can reproduce the bug(?) with a sample project.

      The PostgreSQL 16.4 table looks like:

      create table test(id serial, tm timestamptz);

      I inserted a few rows with now() as timestamp, a select works fine:
      testdb=# select * from test;
      id | tm ---+------------------------------
      1 |2024-10-12 08:56:00.330157+02
      2 |2024-10-12 08:56:03.243138+02
      3 |2024-10-12 08:56:04.754017+02
      (3 rows)
       
      Querying this table with a QSqlQuery object under 6.7.3 shows the expected behavior:{{}}
      true
      QVariant(int, 1) QVariant(QDateTime, QDateTime(2024-10-12 08:56:00.330 Mitteleuropõische Sommerzeit Qt::LocalTime))
      QVariant(int, 2) QVariant(QDateTime, QDateTime(2024-10-12 08:56:03.243 Mitteleuropõische Sommerzeit Qt::LocalTime))
      QVariant(int, 3) QVariant(QDateTime, QDateTime(2024-10-12 08:56:04.754 Mitteleuropõische Sommerzeit Qt::LocalTime))
       
      Just recompile with Qt 6.8 and the result looks like:
      true
      QVariant(int, 1) QVariant(QDateTime, QDateTime(Invalid))
      QVariant(int, 2) QVariant(QDateTime, QDateTime(Invalid))
      QVariant(int, 3) QVariant(QDateTime, QDateTime(Invalid))
      {{}}
      So I cannot access timestamp values anymore. Date values are working fine, simple time field not tested.
      {{}}
      BR Henning
      {{}}
      Source:
       {{}}

      int main(int argc, char* argv[]) 
      { 
        QCoreApplication a(argc, argv); 
        auto db = QSqlDatabase::addDatabase("QPSQL"); 
        db.setHostName("loggix"); 
        db.setDatabaseName("testdb"); 
      
        qDebug() << db.open(); 
      
        auto query = QSqlQuery(db); 
      
        if (!query.exec("select * from test")) 
        { 
          qDebug() << db.lastError().text(); return 1; 
        } 
      
        while (query.next()) 
        { 
          qDebug() << query.value("id") << query.value("tm"); 
        } 
      
      return 0; }

      {{}}

      Attachments

        Issue Links

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

          Activity

            People

              chehrlic Christian Ehrlicher
              hfolger Henning Folger
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes