Qt SQL Query 'Parameter count mismatch' Problem
-
Hello,
I am trying to use binding function of SQL Query but I have encountered a problem.
I execute query like this:
QSqlQuery query; q = QString("insert into records (id, name, surname, info) values (123, 'asd', 'qqq', ':info')"); query.prepare(q); query.bindValue(":info", "KKKKKK"); qDebug() << query.boundValues(); if(!query.exec(q)) { qDebug("Failed to query database: %s", qPrintable(query.lastError().text())); }
This query actually works, because there is NO value to be bound and info field in my row becomes ":info".
Then I change
':info'
to:info
. Now I should be able to use binding feature, but it doesnt work. It gives me this error:QMap((":info", QVariant(QString, "KKKKKK"))) Failed to query database: Parameter count mismatch
I tried to solve this problem from internet but everyone says something wrong in field names itself etc. Thats why I gave you the code without binding things.
I am using Qt 5.11.2 on Ubuntu 18.04. DB is SQLite which has default settings.
-
@maydin said in Qt SQL Query 'Parameter count mismatch' Problem:
if(!query.exec(q))
This is not what you want since you're now simply executing the given query. You want
if (!query.exec())
-
@Christian-Ehrlicher Thanks. I literally wasted 2 hours to find this out. There are lots of things similar to this and all of these are decreasing my motivation.
Idk, I think there should be a warning in function exec(q), since if you prepare something, you probably will not use the "bad" function.