QSqlDatabase::tables(QSql::Tables) includes sqlite_sequence



  • Hi
    A call to QSqlDatabase::tables(QSql::Tables) returns in addition to the user tables also sqlite_sequence. This table is used by sqlite3 to manage autoincrement values. Thus, sqlite_sequence is in my opinion an internal table and should be returned only by a call QSqlDatabase::tables(QSql::SystemTables) and not by QSqlDatabase::tables(QSql::Tables).
    Do I miss something or is this a bug?
    Best
    Al_



  • SQLite itself does not treat it as a system table, and so does Qt. Only sqlite_master is considered beeing a system table.

    I, however, admit that the line for sqlite_sequence is quite blurry, but the choice for SQLite consistency sounds reasonable. Maybe the documentation should be updated to reflect this situation.



  • Thanks for your reply, Lukas. Why do you conclude that sqlite_master is the only system table? The commandline tool sqlite3 (as tested on linux) offers a command .tables . This command does not return sqlite_sequence nor, of course, sqlite_master (but sqlite_sequence exists in the test database, as confirmed by "select * from sqlite_sequence;"). Thus, this tool, to my knowledge from the authors of the database specs, considers sqlite_sequence a system table.



  • In SQLite there are just two tables, sqlite_master and sqlite_temp_master, which are not of type table (<code>SELECT name FROM sqlite_master WHERE type = 'table'</code>).

    The decision was made to interpret <code>QSql::Tables - All the tables visible to the user</code> in a way that it lists all of the database objects of type table, because these are the tables visible and modifiable by the user - and I find this decision reasonable (but not necessarily correct).

    But as said, the line is quite blurry. It is absolutely valid to be of the opinion that those tables should not be included in <code>QSql::Tables</code>, but rather in <code>QSql::SystemTables</code>.

    Feel free to file a "bug report":https://bugreports.qt-project.org/. "Patches":https://codereview.qt-project.org/ are welcome as well.

    Until then just mask out <code>sqlite_</code> database objects as the <code>.tables</code> command does (<code>... AND name NOT LIKE 'sqlite_%'</code> resp. <code>tables().filter(QRegularEpression("^(?!sqlite_).+"))</code>).



  • You convinced me that this is a peculiarity (bug?) of sqlite, not of Qt. I filed a bug-report suggesting a hint in the Qt documentation. See https://bugreports.qt-project.org/browse/QTBUG-28887


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.