[Solved] SQLite: pragma foreign_key_check



  • I try to execute a QSqlQuery for the following pragma command (sqlite) but it does not return the expected results.

    QSqlQuery q("pragma foreign_key_check")

    The expected result would be to return the 4 columns table with all foreign key constrains violations. I have entered in purpose some violations but it returns an empty record (q.size() == -1). From sqlite studio I am able to see the results of this commands. no through Qt though.

    Other pragma commands like "pragma foreign_key_list(tablename)" work fine.

    Can anyone explain why "pragma foreign_key_check" command does not return any result when it should?



  • Check if the SQLite driver in your Qt is 3.7.16 or higher, because that's the version in which this pragma was introduced. To check version execute query:

    SELECT sqlite_version()



  • Thank you googie!
    The problem was exactly that. I had driver version 3.6.19 and now I updated to 3.8.4.3 and the problem solved!

    Just for reference the q.size() is again -1 but the violations are returned correctly.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    IIRC, not all database drivers support returning query sizes. You can check with QSqlDriver::hasFeature(QSqlDriver::QuerySize);


Log in to reply
 

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