Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. [Qt 5.2 msvc x64] QMYSQL invalid driver handle
Qt 6.11 is out! See what's new in the release blog

[Qt 5.2 msvc x64] QMYSQL invalid driver handle

Scheduled Pinned Locked Moved 3rd Party Software
7 Posts 3 Posters 5.2k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    konserw
    wrote on last edited by
    #1

    Hello all, as this is my first post :)
    Ad meritum:
    QMYSQL driver return incorrect driver handle (i think), as following snippet throws "read access voilation" exception with mysql_ping function:
    @
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", "initialConnection");
    if(!db.isValid())
    {
    qCritical() << "Initial connection invalid!";
    return QStringList();
    }
    db.setHostName("192.168.1.2");
    db.setPort(3306);
    db.setUserName("kOf_GetUsers");
    db.setPassword("");
    db.setDatabaseName("kOferta");
    db.setConnectOptions("CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1;MYSQL_OPT_RECONNECT=1");

    qDebug() << "connName:" << db.connectionName();
    qDebug() << "driver:" << db.driverName();
    qDebug() << "options:" << db.connectOptions();
    qDebug() << "host:" << db.hostName();
    qDebug() << "database error:" << db.lastError().databaseText();
    qDebug() << "driver error:" << db.lastError().driverText();

    QSqlDriver* driver = db.driver();
    qDebug() << "driver info";
    driver->dumpObjectInfo();
    driver->dumpObjectTree();

    QVariant v = driver->handle();
    if (v.isValid() && qstrcmp(v.typeName(), "MYSQL*")==0)
    {
    qDebug() << "v.typename:" << v.typeName();

    MYSQL *handle = static_cast<MYSQL *>(v.data());
    if (handle != NULL)
    {
        qDebug() << "handle:" << handle;
        qDebug() << "mysql error:" << mysql_error(handle);
    
        try
        {
            qDebug() << "mysql ping:" << mysql_ping(handle);
            qDebug() << "mysql error:" << mysql_error(handle);
    
    //                mysql_ssl_set(handle, ":/client-key", ":/client-cert", ":/ca-cacert", NULL, NULL);
     //       mysql_ssl_set(handle, "D:/git/build-kOferta/client-key.pem", "D:/git/build-kOferta/client-cert.pem", "D:/git/build-kOferta/ca-cacert.pem", "D:/git/build-kOferta/", "DHE-RSA-AES256-SHA");
        }
        catch (std::exception& e)
        {
            qCritical() << "[mysql_ssl_set] Standard exception: " << e.what();
        }
        catch(...)
        {
            qCritical() << "[mysql_ssl_set] Unknown exception";
        }
    }
    

    }
    @
    And my log is as follows:
    @
    [28.12.2013 11:09:47]: connName: "initialConnection"
    [28.12.2013 11:09:47]: driver: "QMYSQL"
    [28.12.2013 11:09:47]: options: "CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1;MYSQL_OPT_RECONNECT=1"
    [28.12.2013 11:09:47]: host: "192.168.1.2"
    [28.12.2013 11:09:47]: database error: ""
    [28.12.2013 11:09:47]: driver error: ""
    [28.12.2013 11:09:47]: driver info
    [28.12.2013 11:09:47]: OBJECT QMYSQLDriver::unnamed
    [28.12.2013 11:09:47]: SIGNALS OUT
    [28.12.2013 11:09:47]: <None>
    [28.12.2013 11:09:47]: SIGNALS IN
    [28.12.2013 11:09:47]: <None>
    [28.12.2013 11:09:47]: QMYSQLDriver::
    [28.12.2013 11:09:47]: v.typename: MYSQL*
    [28.12.2013 11:09:47]: handle: 0x2c99f0
    [28.12.2013 11:09:47]: mysql error:
    @

    What else can i check? What may be the cause? I use libmysql from MySQL Connector C 6.1 6.1.2 - i dont know if it is relevant...

    Best regards, konserw

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mapron
      wrote on last edited by
      #2

      @ MYSQL *handle = *static_cast<MYSQL **>(v.data());@
      and
      @MYSQL *handle = static_cast<MYSQL *>(v.data());@
      seems to be different lines according to docs (different pointer addresses).
      Could you try another variant?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mapron
        wrote on last edited by
        #3

        if we have CustomType inside Qvariant, type() will be CustomType and .data() return pointer to CustomType.
        If your type is pointer to MYSQL... maybe that is the point?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          konserw
          wrote on last edited by
          #4

          Thank you very much. Casting to MYSQL** helped.
          I wonder when this was changed, becouse cast to MYSQL* worked in qt 4.8...

          1 Reply Last reply
          0
          • K Offline
            K Offline
            konserw
            wrote on last edited by
            #5

            Ok, not realy helped, because dereferenced MYSQL** is NULL, so either thios cast is wrong, or something with my database connection code :/
            Could anyone help me with that? Mabey some working example, how this should be done?

            1 Reply Last reply
            0
            • K Offline
              K Offline
              konserw
              wrote on last edited by
              #6

              ok, it's bug in QMYSQL:
              https://bugreports.qt-project.org/browse/QTBUG-3500#comment-226912

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dawidos
                wrote on last edited by
                #7

                I've used this patch/diff from post above on QT 5.2. Then I've recompiled QT and seems working, but I have to made some tests to make sure that everything is fine. konserw if you want you can email to me

                KR Dawid

                1 Reply Last reply
                0

                • Login

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