Marina K.
20th June 2011, 18:07
Hi everyone,
i'm trying to execute sql command, but everytime i get an error "Parameter count mismatch".
Looking other examples i think that sql syntax is ok. Maybe i'm wrong, that's why i'm asking your help :)
Please, can someone tell what is wrong with code?
This is the code:
QSqlQuery query;
QString strQ = "INSERT INTO item(dict_id, word, prefix, translated, audioPath, example, pronunciation, wordtype, synonyms) VALUES(?,?,?,?,NULL,?,?,?,?)";
qDebug() <<"PREPARE: " << query.prepare(strQ);
query.bindValue(0, QVariant(_dictID));
query.bindValue(1, QVariant(word));
query.bindValue(2, QVariant(clan));
query.bindValue(3, QVariant(translated));
query.bindValue(4, QVariant(example));
query.bindValue(5, QVariant(pronun));
query.bindValue(6, QVariant(wordType));
query.bindValue(7, QVariant(synonym));
if(query.exec(strQ))
{
qDebug() << "Query exec YES";
MyMessageBox mb;
mb.setStyleSheet("background-color:white; color:black;");
mb.setText("A new word is added: " + word);
mb.setIconPixmap(QPixmap(":111.png"));
mb.setStandardButtons(QMessageBox::Ok);
mb.setAutoClose(true);
mb.setTimeOut(2);
mb.exec();
}
else
{
QMessageBox::warning(this, "Adding of word ", "A new word is not added",QMessageBox::Ok);
qDebug()<<query.lastError().text() << query.boundValues().count();
}
And this is output:
PREPARE: true
" Parameter count mismatch" 0
Thx a lot for any suggestion ;):)
i'm trying to execute sql command, but everytime i get an error "Parameter count mismatch".
Looking other examples i think that sql syntax is ok. Maybe i'm wrong, that's why i'm asking your help :)
Please, can someone tell what is wrong with code?
This is the code:
QSqlQuery query;
QString strQ = "INSERT INTO item(dict_id, word, prefix, translated, audioPath, example, pronunciation, wordtype, synonyms) VALUES(?,?,?,?,NULL,?,?,?,?)";
qDebug() <<"PREPARE: " << query.prepare(strQ);
query.bindValue(0, QVariant(_dictID));
query.bindValue(1, QVariant(word));
query.bindValue(2, QVariant(clan));
query.bindValue(3, QVariant(translated));
query.bindValue(4, QVariant(example));
query.bindValue(5, QVariant(pronun));
query.bindValue(6, QVariant(wordType));
query.bindValue(7, QVariant(synonym));
if(query.exec(strQ))
{
qDebug() << "Query exec YES";
MyMessageBox mb;
mb.setStyleSheet("background-color:white; color:black;");
mb.setText("A new word is added: " + word);
mb.setIconPixmap(QPixmap(":111.png"));
mb.setStandardButtons(QMessageBox::Ok);
mb.setAutoClose(true);
mb.setTimeOut(2);
mb.exec();
}
else
{
QMessageBox::warning(this, "Adding of word ", "A new word is not added",QMessageBox::Ok);
qDebug()<<query.lastError().text() << query.boundValues().count();
}
And this is output:
PREPARE: true
" Parameter count mismatch" 0
Thx a lot for any suggestion ;):)