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

QSqlDatabase::removeDatabase prints misleading warning

    XMLWordPrintable

Details

    Description

      When running the following example where the datasource is an ODBC source to a MySQL database, then Qt prints

      "QSqlDatabasePrivate::removeDatabase: connection 'MySQL' is still in use, all queries will cease to work."

      There is no reason for this warning, all QSqlQuery objects have been destroyed.

      #include <QCoreApplication>
      #include <QSqlDatabase>
      #include <QSqlQuery>
      
      #define CONNECTION_NAME "MySQL"
      #define DATABASE_NAME "MySQL"
      #define TABLE_NAME "dept"
      
      void func()
      {
          QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", CONNECTION_NAME);
          db.setDatabaseName(DATABASE_NAME);
          if (db.open()) {
              
              QSqlQuery query(db);
              query.exec(QString("SELECT * FROM %1").arg(TABLE_NAME));
              
              while (query.next())
                  ;
          }
          
          db.close();
          QSqlDatabase::removeDatabase(CONNECTION_NAME);
      }
      
      int main(int argc, char *argv[])
      {
       QCoreApplication a(argc, argv);
      
       func();
      
       return 0;
      }
      

      Attachments

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

        Activity

          People

            bilking Bill King
            vhilshei Volker Hilsheimer
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes