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

ibase driver returns stale error condition

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2: Important P2: Important
    • 6.8.0 Beta3, 6.9.0 FF
    • 6.5.6
    • SQL Support
    • None
    • 9844da503 (dev), f18862e91 (6.8)

      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).

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

            chehrlic Christian Ehrlicher
            hmoffatt Hamish Moffatt
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes