PDA

View Full Version : QSqlDatabase::tables() returns all tables in all databases not just selected database



bazvic
12th July 2010, 10:21
I am using Qt 4.6.2 and accessing a MySQL database. When I use QSqlDatabase::tables the list is of all tables in the all of the databases at the server.

Is this expected behaviour? Is there a way to limit the table list to the selected database?

tbscope
12th July 2010, 10:51
Your answer in 5 seconds:
http://doc.qt.nokia.com/4.6/qsqldatabase.html#tables
and
http://doc.qt.nokia.com/4.6/qsql.html#TableType-enum

How to limit the list?
Simple, perform a query

bazvic
12th July 2010, 21:07
Alas the call does not do what the docs say. The databases should be isolated. QSqlDatabase::tables() should return only the tables for the selected database. Otherwise the result is confusion.

I know under MySQL SHOW TABLES gives me the database tables list. But this may not be portable across different databases.

ChrisW67
12th July 2010, 23:38
The docs for the default QSql::Tables reads "All the tables visible to the user." That is, if your database user can access it then it will show. If you connect as the "root" user you will see everything. You seem to be complaining that it does this while also claiming the docs are wrong.

You should perhaps look at the INFORMATION_SCHEMA tables. These are present in MySql, Microsoft Sql Server, Oracle, Postgresql and Sqlite as part of ANSI compliance.

bazmrl
13th July 2010, 05:17
I see what you mean. What I am seeing is all tables on the server. The problem is that where two or more databases on the same server have tables with the same name there is ambiguity. Under Qt3 QSqlDatabase::tables only returned tables for the selected database. I would expect the same result as SHOW TABLES.

Thanks for your comments.