QSqlError("", "Parameter count mismatch", "")
-
I create the table with sqliteStudio framework
CREATE TABLE "history" ( "incId" INTEGER PRIMARY KEY AUTOINCREMENT, "Id" STRING, "MediHistory" BOOLEAN, "MediType" STRING, "HearHistory" BOOLEAN, "DiaHistory" BOOLEAN, "HyperHistory" BOOLEAN, "Host" BOOLEAN, "HostCause" STRING, "DiriHistory" BOOLEAN, "SmoHistory" BOOLEAN, "PsyHistory" BOOLEAN, "PsyType" STRING, "Shock" BOOLEAN, "Wave" BOOLEAN, "Menu" BOOLEAN, "MenuDate" DATE, "Irregular" BOOLEAN, "MakerUse" BOOLEAN, FOREIGN KEY("Id") REFERENCES "identity"("Id") );
And this is the insert function in .cpp:
void DBmodify::dbinsertHistory(QString Id, bool MediHistory, QString MediType, bool HearHistory , bool DiaHistory, bool HyperHistory, bool Host, QString HostCause, bool DiriHistory, bool SmoHistory, bool PsyHistory, QString PsyType, bool Shock, bool Wave, bool Menu, QDate MenuDate, bool Irregular, bool MakerUse) { QSqlQuery qry(db); qry.prepare("INSERT INTO history (Id, Medi, MediType, HearHistory , DiaHistory, HyperHistory, Host, HostCause, DiriHistory, SmoHistory, PsyHistory, PsyType, EmotionShock, WsveProximity, Menopause,MenstruationDate, Irregular,MakerUse) VALUES (:Id, :MediHistory, :MediType, :HearHistory , ;DiaHistory, :HyperHistory, :Host, :HostCause, :DiriHistory, :SmoHistory, :PsyHistory, :PsyType, :Shock, :Wave, :Menu,:MenuDate, :Irregular,:MakerUse)"); qry.bindValue(":Id", Id); qry.bindValue(":MediHistory", MediHistory); qry.bindValue(":MediType", MediType); qry.bindValue(":HearHistory", HearHistory); qry.bindValue(":DiaHistory", DiaHistory); qry.bindValue(":HyperHistory", HyperHistory); qry.bindValue(":Hospt", Hospt); qry.bindValue(":HostCause", HostCause); qry.bindValue(":DiriHistory", DiriHistory); qry.bindValue(":SmoHistory", SmoHistory); qry.bindValue(":PsyHistory", PsyHistory); qry.bindValue(":PsyType", PsyType); qry.bindValue(":Shock", Shock); qry.bindValue(":Wave",Wave ); qry.bindValue(":Menu",Menu ); qry.bindValue(":MenuDate",MenuDate ); qry.bindValue(":Irregular", Irregular); qry.bindValue(":MakerUse", MakerUse); if( !qry.exec() ) qDebug() << qry.lastError(); else qDebug( "history Inserted!" ); }
And this is when I call it in mainwindow:
connect(ui->next2, SIGNAL(clicked(bool)),this,SLOT(Dsave_clicked())); void Hear::Dsave_clicked() { QDate MenstruationDate=ui->dateEdit->date(); dbFile->dbinsertHistory(get_Id,ui->checkBox_medi->checkState(),get_mediType,ui->checkBox_hear->checkState(),ui->checkBox_dia->checkState(), ui->checkBox_hyper->checkState(),ui->checkBox_host->checkState(),get_host,ui->checkBox_diri->checkState(),ui->checkBox_smo->checkState(),ui->checkBox_psy->checkState(),get_psy, ui->checkBox_shock->checkState(),ui->checkBox_wave->checkState(),ui->checkBox_menu->checkState(),MenuDate,ui->checkBox_Irregular->checkState(),ui->checkBox_maker->checkState()); }
But when I call the insert, output of query is : QSqlError("", "Parameter count mismatch", "")
Where is the problem? -
Hi,
What version of Qt are you using ? Proper support for named place holder in SQLite is recent.
-
@zhmh said in QSqlError("", "Parameter count mismatch", ""):
qry.prepare("INSERT INTO history (Id, Medi, MediType, HearHistory , DiaHistory, HyperHistory, Host, HostCause, DiriHistory, SmoHistory, PsyHistory, PsyType, EmotionShock, WsveProximity, Menopause,MenstruationDate, Irregular,MakerUse) VALUES (:Id, :MediHistory, :MediType, :HearHistory , ;DiaHistory, :HyperHistory, :Host, :HostCause, :DiriHistory, :SmoHistory, :PsyHistory, :PsyType, :Shock, :Wave, :Menu,:MenuDate, :Irregular,:MakerUse)");
Your query is wrong, see DiaHistory
-
@zhmh said in QSqlError("", "Parameter count mismatch", ""):
qry.prepare("INSERT INTO history (Id, Medi, MediType, HearHistory , DiaHistory, HyperHistory, Host, HostCause, DiriHistory, SmoHistory, PsyHistory, PsyType, EmotionShock, WsveProximity, Menopause,MenstruationDate, Irregular,MakerUse) VALUES (:Id, :MediHistory, :MediType, :HearHistory , ;DiaHistory, :HyperHistory, :Host, :HostCause, :DiriHistory, :SmoHistory, :PsyHistory, :PsyType, :Shock, :Wave, :Menu,:MenuDate, :Irregular,:MakerUse)");
Your query is wrong, see DiaHistory
@christian-ehrlicher tnx
I fixed it but still I get same error -
Hi,
What version of Qt are you using ? Proper support for named place holder in SQLite is recent.
-
-
@christian-ehrlicher tnx
I fixed it but still I get same error@zhmh said in QSqlError("", "Parameter count mismatch", ""):
I fixed it but still I get same error
And you did not check the rest? You should... I won't check all parameters for you for typos (there is at least on more in there)
/edit: Ah, @SGaist was faster...
-
@zhmh said in QSqlError("", "Parameter count mismatch", ""):
I fixed it but still I get same error
And you did not check the rest? You should... I won't check all parameters for you for typos (there is at least on more in there)
/edit: Ah, @SGaist was faster...
@christian-ehrlicher you said Right
It's solved ,tnx