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?
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?
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
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.
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.
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.
Bookmarks