Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. BaseResult::exec: Parameter mismatch
Qt 6.11 is out! See what's new in the release blog

BaseResult::exec: Parameter mismatch

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 4 Posters 9.1k Views 3 Watching
  • 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.
  • V Offline
    V Offline
    Vitaliy WH
    wrote on last edited by
    #1

    Hi!
    An error occurred while editing the data in QSqlRelationalTableModel/QSqlTableModel.

    Error: QIBaseResult::exec: Parameter mismatch, expected 0, got 2 parameters

    Database Firebird 3.0, Qt 5.8, OS Ubuntu
    If use database MySQL, error does not occur, everything works.
    What could be the problem?

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

      Hi and welcome to devnet,

      Can you show the query you are using ?

      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
      1
      • V Offline
        V Offline
        Vitaliy WH
        wrote on last edited by kshegunov
        #3

        I do not use the request, I'm using QTableView + QSqlRelationalTableModel

        #include "listform.h"
        #include <QVBoxLayout>
        #include <QAbstractItemView>
        #include <QHeaderView>
        #include <QSqlRelationalDelegate>
        
        ListForm::ListForm(QWidget *parent)
        {
            QVBoxLayout *vl = new QVBoxLayout(parent);
            toolBar = new QToolBar(parent);
            tableView = new QTableView(parent);
            tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
            tableView->setSelectionMode(QAbstractItemView::SingleSelection);
            tableView->resizeColumnsToContents();
            tableView->horizontalHeader()->setStretchLastSection(true);
            tableView->setItemDelegate(new QSqlRelationalDelegate);
        
        
            vl->addWidget(toolBar);
            vl->addWidget(tableView);
        
            this->setLayout(vl);
        
            actionNew = new QAction(toolBar);
            actionNew->setIcon(QIcon(":images/new.png"));
        
            actionEdit = new QAction(toolBar);
            actionEdit->setIcon(QIcon(":images/edit.png"));
        
            actionDelete = new QAction(toolBar);
            actionDelete->setIcon(QIcon(":images/delete.png"));
        
            actionRefresh = new QAction(toolBar);
            actionRefresh->setIcon(QIcon(":images/refresh.png"));
        
            toolBar->addAction(actionNew);
            toolBar->addAction(actionEdit);
            toolBar->addSeparator();
            toolBar->addAction(actionDelete);
            toolBar->addSeparator();
            toolBar->addAction(actionRefresh);
        }
        
        void ListForm::setModel(QSqlRelationalTableModel *model)
        {
            tableView->setModel(model);
        
        }
        
        MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
        
            QSqlDatabase db = QSqlDatabase::addDatabase("QIBASE");
            db.setHostName("localhost");
            db.setDatabaseName("/home/vital/WMS/db/wms.fdb");
            db.setUserName("SYSDBA");
            db.setPassword("masterkey");
        
        //    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
        //    db.setHostName("localhost");
        //    db.setDatabaseName("jTrade");
        //    db.setUserName("root");
        //    db.setPassword("Gladiator#2017");
        
            if (!db.open()) {
                qDebug() << "Cannot open DB!" << db.lastError();
            } else
                qDebug() << "Connect to DB!";
        
        
            QSqlRelationalTableModel *model = new QSqlRelationalTableModel(this);
            model->setTable("users");
            model->setRelation(model->fieldIndex("id_employee"),QSqlRelation("employees","id","name"));
            model->select();
            model->setEditStrategy(QSqlTableModel::OnRowChange);
            model->setSort(model->fieldIndex("name"),Qt::AscendingOrder);
        
            ListForm *lf = new ListForm();
            lf->setParent(this,Qt::Window);
            lf->show();
            lf->setModel(model);
        }
        

        [Added code tags ~kshegunov]

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

          You should check last error and query from your model. That might give you more clues about what is happening.

          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
          1
          • V Offline
            V Offline
            Vitaliy WH
            wrote on last edited by
            #5

            QT sent query:
            UPDATE users SET "PASSWD"=? WHERE "users"."ID" = ?
            On request it is visible that parameters are not set
            The question is why?

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

              Looks like prepared query with anonymous placeholders.

              When exactly is that one called ?

              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
              1
              • V Offline
                V Offline
                Vitaliy WH
                wrote on last edited by
                #7

                When to we apply changes. In my case, when we move to new row in QTableView, this query sent to server. It turns out, Qt do not fill query parameters. How to solve this problem?

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

                  It's not very clear. Do you mean it happens when you add a new row ?

                  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
                  0
                  • V Offline
                    V Offline
                    Vitaliy WH
                    wrote on last edited by
                    #9
                    model->setEditStrategy(QSqlRelationalTableModel::OnRowChange);
                    
                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      Vitaliy WH
                      wrote on last edited by
                      #10

                      After changing the line, we go to another line. Changes are sent to the server Firebird. Query we transmitted to server by QSqlRelationalTableModel, but without filling in the parameters. Parameters must fill in QSqlRelationalTableModel, but it does not work for Firebird. With MySQL, there are no such problems.
                      Sorry for bad English

                      1 Reply Last reply
                      0
                      • N Offline
                        N Offline
                        Navodar
                        wrote on last edited by Navodar
                        #11

                        I have similar problem:

                            query.prepare("INSERT INTO MATERIJALI(NAZIV, STANJE_U_SILOSU, ZADNJA_POTROSNJA) VALUES(:naz, :sil, :pot)");
                            query.bindValue(":naz", ui->eNaziv->text());
                            query.bindValue(":sil", ui->eStanje->value());
                            query.bindValue(":pot", ui->eDatum->dateTime().toString());
                        

                        return: QIBaseResult::exec: Parameter mismatch, expected 0, got 3 parameters

                        It seems that QIBaseDriver don't support named placeholders. But when I try with positional placeholders, the result is the same:

                            query.prepare("INSERT INTO MATERIJALI(NAZIV, STANJE_U_SILOSU, ZADNJA_POTROSNJA) VALUES(?, ?, ?)");
                            query.bindValue(0, ui->eNaziv->text());
                            query.bindValue(1, ui->eStanje->value());
                            query.bindValue(2, ui->eDatum->dateTime().toString());
                        

                        "QIBaseResult::exec: Parameter mismatch, expected 0, got 3 parameters".

                        jsulmJ 1 Reply Last reply
                        0
                        • N Navodar

                          I have similar problem:

                              query.prepare("INSERT INTO MATERIJALI(NAZIV, STANJE_U_SILOSU, ZADNJA_POTROSNJA) VALUES(:naz, :sil, :pot)");
                              query.bindValue(":naz", ui->eNaziv->text());
                              query.bindValue(":sil", ui->eStanje->value());
                              query.bindValue(":pot", ui->eDatum->dateTime().toString());
                          

                          return: QIBaseResult::exec: Parameter mismatch, expected 0, got 3 parameters

                          It seems that QIBaseDriver don't support named placeholders. But when I try with positional placeholders, the result is the same:

                              query.prepare("INSERT INTO MATERIJALI(NAZIV, STANJE_U_SILOSU, ZADNJA_POTROSNJA) VALUES(?, ?, ?)");
                              query.bindValue(0, ui->eNaziv->text());
                              query.bindValue(1, ui->eStanje->value());
                              query.bindValue(2, ui->eDatum->dateTime().toString());
                          

                          "QIBaseResult::exec: Parameter mismatch, expected 0, got 3 parameters".

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @Navodar What does http://doc.qt.io/qt-5/qsqlquery.html#executedQuery show?

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          N 1 Reply Last reply
                          0
                          • jsulmJ jsulm

                            @Navodar What does http://doc.qt.io/qt-5/qsqlquery.html#executedQuery show?

                            N Offline
                            N Offline
                            Navodar
                            wrote on last edited by
                            #13

                            @jsulm here is result of executedQuery():
                            "INSERT INTO MATERIJALI(NAZIV, STANJE_U_SILOSU, ZADNJA_POTROSNJA) VALUES(?, ?, ?)"

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

                              What if you use addBindValue rather than bindValue ?

                              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
                              0
                              • N Offline
                                N Offline
                                Navodar
                                wrote on last edited by
                                #15

                                With:

                                    query.addBindValue(ui->eNaziv->text());
                                    query.addBindValue(ui->eStanje->value());
                                    query.addBindValue(ui->eDatum->dateTime().toString());
                                

                                result is the same: QIBaseResult::exec: Parameter mismatch, expected 0, got 3 parameters

                                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
                                • Unsolved