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

If SQL Engine does not support lastInsertId QList will assert

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P1: Critical
    • 6.6.3, 6.7.0 RC, 6.8.0 FF
    • 6.6.1
    • SQL Support
    • None
    • Visual Studio 2022
    • All
    • 6287daaa2 (dev), 8b100d89f (6.7), e9ea5213a (6.6)

    Description

      The following code on a MDB Database that is called by ODBC triggers a debug break:

       

      QSqlQuery insertQuery(database);
      if (insertQuery.prepare("INSERT INTO Ereignisse (Typ, SubTyp, TypDauerUndStatus, DatumBeginn, DatumEnde, PatientenNummer, AuswertungsNummer, BenutzerNummer, ProjektNummer, PCName, Status) VALUES (:typ, :subtyp, :typDauerUndStatus, :DatumBeginn, :DatumEnde, :PatientenNummer, :AuswertungsNummer, :BenutzerNummer, :ProjektNummer, :PCName, :Status)") == false)
      {
          return tr("Could not insert entry into database. Maybe the database is not writable? %1").arg(insertQuery.lastError().text());
      }
      insertQuery.bindValue(":typ", 0);
      insertQuery.bindValue(":subtyp", 0);
      insertQuery.bindValue(":typDauerUndStatus", 0);
      insertQuery.bindValue(":DatumBeginn", QDateTime::currentDateTime());
      insertQuery.bindValue(":DatumEnde", QDateTime::currentDateTime());
      insertQuery.bindValue(":PatientenNummer", -1);
      insertQuery.bindValue(":AuswertungsNummer", -1);
      insertQuery.bindValue(":BenutzerNummer", -1);
      insertQuery.bindValue(":ProjektNummer", 107);
      insertQuery.bindValue(":PCName", "TEST");
      insertQuery.bindValue(":Status", 0);
      
      if (insertQuery.exec() == false)
      {
          return tr("Could not insert entry into database. Maybe the database is not writable? %1").arg(insertQuery.lastError().text());
      }
      
      int insertID = insertQuery.lastInsertId().toInt();

      The problem is that this will trigger an error in qsql_odbc.cpp line 1740:

      qSqlWarning("QODBCResult::lastInsertId: not implemented for this DBMS"_L1, d); 

      Following the stacktrace it wants to print out diagnostic information that are held in a QList that is empty.

      in qsql_odbc.cpp line 264 this function is wrong:

      static DiagRecord combineRecords(const QList<DiagRecord> &records)
      {
          const auto add = [](const DiagRecord &a, const DiagRecord &b) {
              return DiagRecord{a.description + u' ' + b.description,
                                a.sqlState + u';' + b.sqlState,
                                a.errorCode + u';' + b.errorCode};
          };
          return std::accumulate(std::next(records.begin()), records.end(), records.front(), add);
      } 

      records is empty in my case and thus the call to records.front() will trigger an assert on the QList.

       

      Attachments

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

        Activity

          People

            chehrlic Christian Ehrlicher
            davidweisgerber David Weisgerber
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes