PDA

View Full Version : Parameter count mismatch in create table statement



croscato
6th November 2009, 06:34
Hi all! I have the following code to manipulate a sqlite3 database:



const QString SQL_INSERT_LANGUAGE =
"INSERT INTO languages VALUES ("
"null, :language, :abbreviation"
")";

const QString SQL_CREATE_TABLE_WORD =
"CREATE TABLE :table ("
"word VARCHAR UNIQUE, "
"a INT, b INT, c INT, d INT, e INT, f INT, g INT, h INT, "
"i INT, j INT, k INT, l INT, m INT, n INT, o INT, p INT, "
"q INT, r INT, s INT, t INT, u INT, v INT, w INT, x INT, "
"y INT, z INT, "
"len INT"
")";

bool DB::addLanguage(const QVariant & language, const QVariant & abbreviation)
{
QSqlQuery query((*mDatabase));

query.prepare(SQL_INSERT_LANGUAGE);
query.bindValue(":language", language);
query.bindValue(":abbreviation", abbreviation);

if (query.exec() == false) {
qDebug() << "ERROR 1 = " << query.lastError();

return false;
}


query.prepare(SQL_CREATE_TABLE_WORD);
query.bindValue(":table", abbreviation);

if (query.exec() == false) { // The error is in this query
qDebug() << "ERROR 2 = " << query.lastError();
qDebug() << "SQL = " << query.executedQuery();

return false;
}

return true;
}



The first query executes with no problem. But when the second one is executed it give me the "Parameter count mismatch".

Please, can someone help me???

Thanks!!!

lyuts
8th November 2009, 08:02
Did you try to run the same query from the sqlite3 terminal? What are the errors?

croscato
9th November 2009, 11:57
In the sqlite3 terminal it works correctly. I think the problem is in the parameter binding.

ftrastour
9th November 2009, 13:42
Hi,

Are you sure that prepare reset bound values ?

Perhaps could you try to 'clear' the query before to 'prepare' it for the second time.

Fred.

croscato
9th November 2009, 17:08
I have cleared the query but it give me the same error.

I think now that the problem is that the "binding placeholder" is the table name in que Sql statement. I think it only work if you try to bind a parameter.

remy_david
4th February 2011, 09:38
I think it only work if you try to bind a parameter.

That's the case.