Details
-
Bug
-
Resolution: Fixed
-
P1: Critical
-
6.6.1
-
None
-
Visual Studio 2022
-
-
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.