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. SQLite and QSqlQuery "Parameter count mismatch" Error
Forum Updated to NodeBB v4.3 + New Features

SQLite and QSqlQuery "Parameter count mismatch" Error

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 2.8k 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #2

    What Qt version do you use?
    Please check the return values of query.prepare() and bindValue(). Also re-write your query to UPATE summary_payment SET product_name = :product_name, price = :price WHERE id = :id

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

    1 Reply Last reply
    2
    • P Offline
      P Offline
      ppitu
      wrote on last edited by
      #3

      I am using Qt 1.15.1
      I re-write this line but i have still this problem.
      And i check the lastError():
      Parameter count mismatch"
      And lastQuery():
      UPDATE summary_payment SET product_name = :product_name, price = :price WHERE id = :id

      JonBJ 1 Reply Last reply
      0
      • P ppitu

        Hi
        I have a function to update record in database:

        void SummaryPaymentDao::updateSummaryPayment(const SummaryPayment &summaryPayment) const
        {
            qDebug() << summaryPayment.getProductName();
            QSqlQuery query(mDatabase);
            query.prepare("UPDATE summary_payment SET (product_name = :product_name, price = :price) WHERE id = (:id)");
            query.bindValue(":product_name", summaryPayment.getProductName());
            query.bindValue(":price", summaryPayment.getPrice());
            query.bindValue(":id", summaryPayment.getId());
            query.exec();
            qDebug() << query.lastQuery();
            DatabaseManager::debugQuery(query);
        }
        

        But when i call this function i get error:
        "Parameter count mismatch"
        I tried to look for answers on the forum but no solution worked.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #4

        @ppitu
        In addition to @Christian-Ehrlicher 's correction to your syntax.

        SQLite apparently returns "Parameter count mismatch" for "almost any" error :)

        P 1 Reply Last reply
        0
        • P ppitu

          I am using Qt 1.15.1
          I re-write this line but i have still this problem.
          And i check the lastError():
          Parameter count mismatch"
          And lastQuery():
          UPDATE summary_payment SET product_name = :product_name, price = :price WHERE id = :id

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #5

          @ppitu
          What did you do about @Christian-Ehrlicher's

          Please check the return values of query.prepare() and bindValue().

          ?

          We do not know what is in your database. We don't know whether you have a table named summary_payment. We don't know whether it has the column names you specify. We don't know whether your code is supplying good values for these.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by Christian Ehrlicher
            #6

            This works fine for me:

            QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
            db.open();
            QSqlQuery query(db);
            query.exec("CREATE TABLE summary_payment (product_name text, price real, id primary key)");
            query.prepare("UPDATE summary_payment SET product_name = :product_name, price = :price WHERE id = :id");
            query.bindValue(":product_name", QLatin1String("product_name"));
            query.bindValue(":price", 8);
            query.bindValue(":id", 7);
            if (!query.exec()) {
              qDebug() << query.lastError().databaseText() << query.lastError().driverText();
            }
            

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

            1 Reply Last reply
            1
            • JonBJ JonB

              @ppitu
              In addition to @Christian-Ehrlicher 's correction to your syntax.

              SQLite apparently returns "Parameter count mismatch" for "almost any" error :)

              P Offline
              P Offline
              ppitu
              wrote on last edited by
              #7

              https://github.com/ppitu/SummaryPaymentApp/blob/main/summary-payment-app/summary-payment-app-core/SummaryPaymentDao.cpp

              Here is a link to the whole file.
              I create the table the same as @Christian-Ehrlicher , and insert to database work correct i have a problem with update and remove

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #8

                Did you try my code? If so adjust yours until it's working as expected.

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

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  ppitu
                  wrote on last edited by
                  #9

                  @Christian-Ehrlicher i tried your code (in new project) and it worked fine.
                  But when i change code in my app I get this error: "" "Parameter count mismatch"

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    Then simplify your code until it works or looks like mine to find your problem.

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

                    1 Reply Last reply
                    2
                    • P Offline
                      P Offline
                      ppitu
                      wrote on last edited by
                      #11

                      Thanks for help, i found my mistake (in database in table summay_payment i have: summarypayment_id not id)

                      JonBJ 1 Reply Last reply
                      1
                      • P ppitu

                        Thanks for help, i found my mistake (in database in table summay_payment i have: summarypayment_id not id)

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #12

                        @ppitu
                        Which is why, as I suggested, we could not help you.....

                        You really ought take the time to find one of the various free off-line or on-line SQLite workbench tools available to test your queries outside of Qt while you develop them.

                        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