SQL/ODBC: Don't assert when no error record is available

When SQLGetDiagRec() does not return an record, the list of
DiagRecords might be empty. This will create an assertion when trying
to access QList::front() or similar. Therefore we need to check if the
list is empty before accessing it.

This amends 4ec5c0efc7

Fixes: QTBUG-122073
Pick-to: 6.7 6.6
Change-Id: I6f421d82f9b6fdf84672d755cbbe8d2adec13266
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
bb10
Christian Ehrlicher 2024-02-08 17:22:57 +01:00
parent 3fc1adcda5
commit 6287daaa20
1 changed files with 2 additions and 0 deletions

View File

@ -269,6 +269,8 @@ static DiagRecord combineRecords(const QList<DiagRecord> &records)
a.sqlState + u';' + b.sqlState,
a.errorCode + u';' + b.errorCode};
};
if (records.isEmpty())
return {};
return std::accumulate(std::next(records.begin()), records.end(), records.front(), add);
}