Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlError("", "Parameter count mismatch", "")
QtWS25 Last Chance

QSqlError("", "Parameter count mismatch", "")

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 701 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • zhmhZ Offline
    zhmhZ Offline
    zhmh
    wrote on last edited by zhmh
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What version of Qt are you using ? Proper support for named place holder in SQLite is recent.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      zhmhZ 1 Reply Last reply
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by Christian Ehrlicher
        #3

        @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

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        zhmhZ 1 Reply Last reply
        2
        • Christian EhrlicherC Christian Ehrlicher

          @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

          zhmhZ Offline
          zhmhZ Offline
          zhmh
          wrote on last edited by
          #4

          @christian-ehrlicher tnx
          I fixed it but still I get same error

          Christian EhrlicherC 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            What version of Qt are you using ? Proper support for named place holder in SQLite is recent.

            zhmhZ Offline
            zhmhZ Offline
            zhmh
            wrote on last edited by zhmh
            #5

            @sgaist Qt 5.11.2, I have other tables in that database,they work

            `

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Another typo:

              @zhmh said in QSqlError("", "Parameter count mismatch", ""):

              Hospt

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              3
              • zhmhZ zhmh

                @christian-ehrlicher tnx
                I fixed it but still I get same error

                Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by Christian Ehrlicher
                #7

                @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...

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                zhmhZ 1 Reply Last reply
                1
                • Christian EhrlicherC Christian Ehrlicher

                  @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...

                  zhmhZ Offline
                  zhmhZ Offline
                  zhmh
                  wrote on last edited by
                  #8

                  @christian-ehrlicher you said Right
                  It's solved ,tnx

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved