Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. MySQL option MYSQL_OPT_CONNECT_TIMEOUT ignored
QtWS25 Last Chance

MySQL option MYSQL_OPT_CONNECT_TIMEOUT ignored

Scheduled Pinned Locked Moved General and Desktop
mysqlconnectiontimeout
5 Posts 2 Posters 4.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    szergejbubka
    wrote on 3 Oct 2015, 09:54 last edited by
    #1

    The Qt docs (http://doc.qt.io/qt-5/qsqldatabase.html#setConnectOptions) states that the mysql driver accepts the MYSQL_OPT_CONNECT_TIMEOUT option. However it seems to be ignored, and the timeout seems to be about 20-25 seconds when the network is unreachable, independently of what is set with the option.

    QString dbName = "mydb";
        {
            QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", dbName);
            db.setHostName(databaseUrl);
            db.setPort(databasePort);
            db.setDatabaseName(databaseName);
            db.setUserName(databaseUsername);
            db.setPassword(databasePassword);
            db.setConnectOptions("MYSQL_OPT_CONNECT_TIMEOUT=5");
            if(db.open() == false)
                qDebug("Cannot access database");
            else {
                QSqlQuery query = QSqlQuery(db);
                ...
            }
        }
    

    This code blocks in open() for about 20-25 seconds instead of 5. I tried it with Qt 5.5.0 with the patched (https://codereview.qt-project.org/#/c/123488/) mysql plugin in both windows and linux. In windows I had trouble using the mysql library, so I used mariadb instead, but in linux I used the mysql lib, and both seems to ignore the timeout option.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 3 Oct 2015, 21:43 last edited by
      #2

      Hi,

      What MYSQL_VERSION_ID do you have with mariadb ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply 4 Oct 2015, 08:27
      0
      • S SGaist
        3 Oct 2015, 21:43

        Hi,

        What MYSQL_VERSION_ID do you have with mariadb ?

        S Offline
        S Offline
        szergejbubka
        wrote on 4 Oct 2015, 08:27 last edited by
        #3

        @SGaist MYSQL_VERSION_ID is 50500 in mariadb (windows), and it is 50544 in mysql (linux).

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 4 Oct 2015, 22:31 last edited by
          #4

          So since you already applied the patch, I'd recommend checking the return value of mysql_options call that sets the timeout to ensure you don't have anything funky going on there.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            szergejbubka
            wrote on 5 Oct 2015, 07:03 last edited by szergejbubka 10 May 2015, 09:02
            #5

            mysql_options called with MYSQL_OPT_CONNECT_TIMEOUT returns 0 (success) both for mysql and mariadb libraries.

            1 Reply Last reply
            0

            5/5

            5 Oct 2015, 07:03

            • Login

            • Login or register to search.
            5 out of 5
            • First post
              5/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved