I'm doing a simple parameterized query with Qt 5.3.1 (64-bit) on Windows 7 using the SQLite driver. When I use bindValue()
to set the value of the single parameter of my query, I systematically get the dreaded "Parameter count mismatch" error. Everything works fine when I use addBindValue()
. Note that the code with bindValue()
works fine with Qt 4.8.5 (64-bit).
Here is the full code (main.cpp
):
#include <QtSql>
int main(int, char* [])
{
auto db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("db.sqlite");
db.open();
{
QSqlQuery query("CREATE TABLE IF NOT EXISTS hashes (filepath TEXT, modified INTEGER, hash TEXT)", db);
query.exec();
}
QSqlQuery query("SELECT modified FROM hashes WHERE filepath = :fp", db);
query.bindValue(":fp", "test.jpg");
if (!query.exec())
qDebug() << query.lastError();
db.close();
return 0;
}
QtCreator project file (qtsqltest.pro
):
QT += core sql
TARGET = qtsqltest
TEMPLATE = app
SOURCES += main.cpp
Program output on my machine:
QSqlError("", "Parameter count mismatch", "")
Any idea?