Results 1 to 5 of 5

Thread: QSqlDatabase::tables() returns all tables in all databases not just selected database

  1. #1
    Join Date
    Jul 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSqlDatabase::tables() returns all tables in all databases not just 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?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QSqlDatabase::tables() returns all tables in all databases not just selected data

    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

  3. #3
    Join Date
    Jul 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabase::tables() returns all tables in all databases not just selected data

    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.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSqlDatabase::tables() returns all tables in all databases not just selected data

    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.

  5. #5
    Join Date
    Jul 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabase::tables() returns all tables in all databases not just selected data

    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.

Similar Threads

  1. list tables column name (database)
    By baray98 in forum Qt Programming
    Replies: 1
    Last Post: 26th September 2012, 11:18
  2. Replies: 1
    Last Post: 16th May 2010, 19:25
  3. Replies: 4
    Last Post: 14th April 2008, 16:33
  4. tables
    By tommy in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 15:17

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.