Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlQuery Postgres and timestamp => QDateTime(Invalid)
QtWS25 Last Chance

QSqlQuery Postgres and timestamp => QDateTime(Invalid)

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 445 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HenningF
    wrote on last edited by HenningF
    #1

    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.

    Am I doing something wrong, missing to send any additional connection parameter or is it simple a bug?

    BR Henning

    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;
    }
    
    1 Reply Last reply
    0
    • H Offline
      H Offline
      HenningF
      wrote on last edited by
      #6

      I filed a bug report and it seems that the bug is identified and solved.
      Mni tnx,

      BR Henning

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #2

        In the Qt 6.8 announcement was this note, "The PostgreSQL and MySQL/MariaDB drivers now correctly handle date and time data when the server is in a different time zone than the client." So, something changed, perhaps not for the better.

        H 1 Reply Last reply
        0
        • C ChrisW67

          In the Qt 6.8 announcement was this note, "The PostgreSQL and MySQL/MariaDB drivers now correctly handle date and time data when the server is in a different time zone than the client." So, something changed, perhaps not for the better.

          H Offline
          H Offline
          HenningF
          wrote on last edited by
          #3

          @ChrisW67 Yes, I saw that es well, but I guess, some further info is missing here?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            ChrisW67
            wrote on last edited by
            #4

            Possibility that QTBUG-115960 and the associated fix have something to do with this. I cannot quite see it though, and I do not have PostgreSql readily to hand. @Christian-Ehrlicher has his name in the bug commentary; perhaps we will get some further comment.

            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by Christian Ehrlicher
              #5

              I'll take a look on it, thx for the report. Please create a bug report.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0
              • H Offline
                H Offline
                HenningF
                wrote on last edited by
                #6

                I filed a bug report and it seems that the bug is identified and solved.
                Mni tnx,

                BR Henning

                1 Reply Last reply
                0
                • H HenningF has marked this topic as solved on
                • JonBJ JonB referenced this topic on

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved