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
Forum Updated to NodeBB v4.3 + New Features

database.tables() returned empty after connected to mariadb

Scheduled Pinned Locked Moved General and Desktop
qsqldatabase
5 Posts 3 Posters 2.5k 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 13 Mar 2015, 01:36 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 :
    ()

    S 1 Reply Last reply 14 Mar 2015, 23:13
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 14 Mar 2015, 20:27 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 15 Mar 2015, 00:56
      0
      • L lxyevl
        13 Mar 2015, 01:36

        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 :
        ()

        S Offline
        S Offline
        simow
        wrote on 14 Mar 2015, 23:13 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 15 Mar 2015, 01:04
        0
        • S SGaist
          14 Mar 2015, 20:27

          Hi and welcome to devnet,

          Did you rebuild the driver before using it with MariaDB ?

          L Offline
          L Offline
          lxyevl
          wrote on 15 Mar 2015, 00:56 last edited by
          #4

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

          1 Reply Last reply
          0
          • S simow
            14 Mar 2015, 23:13

            @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 15 Mar 2015, 01:04 last edited by
            #5

            @simow thanks for the answer.

            1 Reply Last reply
            0

            1/5

            13 Mar 2015, 01:36

            • Login

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