August 20, 2011

When sqlite queries fail for no reason

If you have worked with QtSql, you might have hit the dreaded “Parameter count mismatch” for your perfectly valid SQL query. The problem is excruciatingly hard to debug because the query itself works perfectly fine with the sqlite3 tool.

Here’s the solution: Compile Qt with -system-sqlite.

The problem: Qt uses it’s own sqlite3 headers under src/3rdparty by default which are completely out of date. Qt 4.7 has sqlite3 header from 2009-10-14 version 3.6.18. Almost 2 years old and current sqlite version is 3.7.7! That’s like using Qt 4.5.3 in 2011 :-) FTS3/4 table queries fail consistently when using Qt’s own headers.

I have opened QTBUG-21040.

7 Responses to “When sqlite queries fail for no reason”

  1. gcala says:

    Which distro are you using? Archlinux and Chakra already use that option.

  2. Girish says:

    @gcala: I always compile Qt from git.

  3. jstaniek says:

    I guess the root issue here is that SQLite does not
    manage versions properly, e.g. it changed the file
    format twice within the major version 4.
    The same header should work within the same major
    version, just you should have less features available when using older header, what could be manifested as error in the linking time.

  4. jstaniek says:

    (I mean major version 3 of course :)

    SQLite should be already numbered as 5 or so.

  5. mmauri says:

    I had problems with foreign key constraint enforcement and I’ve read that in 4.8 they’re going to update the sqlite embedded in qt to a more recent version (that supports foreign key constraint enforcement).

  6. D. Richard Hipp says:

    The SQLite file format has not changed. All SQLite database files going back to version 3.0.0 (2004-06-18) are readable and writable by every version of SQLite published since then.

    Nor has the SQLite API changed. Applications coded against any version of SQLite since 3.0.0 should be able to link and run against the latest SQLite without issue.

    However, you should not mix and match header files with C code files. If you are statically linking sqlite3.c version 3.6.23 then you should use the sqlite3.h for version 3.6.23, not version 3.7.7. This restriction applies to static linking only. In all other ways, the versions of SQLite should be fully interchangeable. If you encounter something different, that is a bug that should be reported.

    Note that we run tests for backwards compatibility prior to every release of SQLite.

  7. Lesli says:

    I almost never leave a response, but i did a few
    searching and wound up here When sqlite queries fail for no reason

Leave a comment

(email will not be published)