database.tables() returned empty after connected to mariadb
-
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 :
() -
Hi and welcome to devnet,
Did you rebuild the driver before using it with MariaDB ?
-
@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 databaseinformation_schema
. When I use another database,tables()
works just fine.
Even when I usedQSqlDatabase::tables(QSql::AllTables)
-- show everything, including system tables -- the ones contained ininformation_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 ininformation_schema
and itself. -
@SGaist No, I didn't. I installed the driver by zypper.
-
@simow thanks for the answer.