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. database.tables() returned empty after connected to mariadb
Qt 6.11 is out! See what's new in the release blog

database.tables() returned empty after connected to mariadb

Scheduled Pinned Locked Moved General and Desktop
qsqldatabase
5 Posts 3 Posters 2.8k Views 3 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.
  • L Offline
    L Offline
    lxyevl
    wrote on last edited by lxyevl
    #1

    After I used driver "QMYSQL" to connect to mariadb, the database.tables() returned

    empty. I have tried qt4.8 and qt5.3.2, got the same result.But when I connected to

    sqlite, there is no problem.

    My OS is opensuse 13.2 64 Bit.

    My code is :
    #include <QSqlDatabase>
    #include <QSqlError>
    #include <QDebug>
    #include <QStringList>

    int main()
    {
    QSqlDatabase database = QSqlDatabase::addDatabase("QMYSQL");
    database.setHostName("localhost");
    database.setUserName("lxy");
    database.setPassword("qqqqqq");
    database.setDatabaseName("information_schema");
    if (!database.open())
    {
    qDebug()<<database.lastError().text();
    return 1;
    }
    qDebug()<<database.tables();
    return 0;
    }

    Program output :
    ()

    simowS 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Did you rebuild the driver before using it 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

      L 1 Reply Last reply
      0
      • L lxyevl

        After I used driver "QMYSQL" to connect to mariadb, the database.tables() returned

        empty. I have tried qt4.8 and qt5.3.2, got the same result.But when I connected to

        sqlite, there is no problem.

        My OS is opensuse 13.2 64 Bit.

        My code is :
        #include <QSqlDatabase>
        #include <QSqlError>
        #include <QDebug>
        #include <QStringList>

        int main()
        {
        QSqlDatabase database = QSqlDatabase::addDatabase("QMYSQL");
        database.setHostName("localhost");
        database.setUserName("lxy");
        database.setPassword("qqqqqq");
        database.setDatabaseName("information_schema");
        if (!database.open())
        {
        qDebug()<<database.lastError().text();
        return 1;
        }
        qDebug()<<database.tables();
        return 0;
        }

        Program output :
        ()

        simowS Offline
        simowS Offline
        simow
        wrote on last edited by simow
        #3

        @lxyevl Hi, I can reproduce your behaviour. The culprit seems to be the database itself. For some reason QSqlDatabase::tables() doesn't like to show the tables from the MySQL internal database information_schema. When I use another database, tables() works just fine.
        Even when I used QSqlDatabase::tables(QSql::AllTables) -- show everything, including system tables -- the ones contained in information_schema didn't show up. Eventually a bug but might also be a security feature of MySQL not to present internal data?
        But I found a workaround. Maybe this would help you:

        QSqlQuery q;
        q.exec( "select TABLE_NAME,TABLE_SCHEMA from TABLES where TABLE_SCHEMA='information_schema' LIMIT 10" );
        while(q.next()) {
         qDebug() << q.value(0) << ", " << q.value(1);
        }
        

        This query selects the name and schema from the information_schema.tables system table that contains the meta data of all tables of all databases -- even those in information_schema and itself.

        Let's Try To Negotiate!

        L 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi and welcome to devnet,

          Did you rebuild the driver before using it with MariaDB ?

          L Offline
          L Offline
          lxyevl
          wrote on last edited by
          #4

          @SGaist No, I didn't. I installed the driver by zypper.

          1 Reply Last reply
          0
          • simowS simow

            @lxyevl Hi, I can reproduce your behaviour. The culprit seems to be the database itself. For some reason QSqlDatabase::tables() doesn't like to show the tables from the MySQL internal database information_schema. When I use another database, tables() works just fine.
            Even when I used QSqlDatabase::tables(QSql::AllTables) -- show everything, including system tables -- the ones contained in information_schema didn't show up. Eventually a bug but might also be a security feature of MySQL not to present internal data?
            But I found a workaround. Maybe this would help you:

            QSqlQuery q;
            q.exec( "select TABLE_NAME,TABLE_SCHEMA from TABLES where TABLE_SCHEMA='information_schema' LIMIT 10" );
            while(q.next()) {
             qDebug() << q.value(0) << ", " << q.value(1);
            }
            

            This query selects the name and schema from the information_schema.tables system table that contains the meta data of all tables of all databases -- even those in information_schema and itself.

            L Offline
            L Offline
            lxyevl
            wrote on last edited by
            #5

            @simow thanks for the answer.

            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