Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.5.6
-
None
-
9844da503 (dev), f18862e91 (6.8)
Description
Using the ibase driver, if you encounter an error, close the connection and re-open it, the re-open will fail returning the original error.
QIBaseDriver::open() checks for an error, but never clears any existing error.
https://github.com/qt/qtbase/blob/dev/src/plugins/sqldrivers/ibase/qsql_ibase.cpp#L1645
I'm testing my connections before use and re-opening them if broken, which isn't working; roughly:
auto database = QSqlDatabase::database(connectionName, false); // If the database claims to be open, check that the connection is valid; // if not, close so it can be reopened if (database.isOpen()) { auto testQuery = database.exec(QStringLiteral("SELECT 1 FROM RDB$DATABASE")); if (auto err = testQuery.lastError(); err.isValid()) { qCDebug(lc) << "Existing connection is stale:" << err.text() << err.nativeErrorCode(); database.close(); } } if (!database.isOpen() && !database.open()) { error = QStringLiteral("%1 (code %2)").arg(database.lastError().text(), database.lastError().nativeErrorCode()); }
The open() call fails because the driver is returning a stale error, because neither close() nor open() reset the last error.
Also, at line 1647, setOpen(true) should surely be setOpenError(true).