Home > Back-end >  SQLite error in QT - QSqlError("", "Parameter count mismatch", "")
SQLite error in QT - QSqlError("", "Parameter count mismatch", "")

Time:05-23

I'm trying to simply count the amount of records that has a 'true' status.

this is the SQLite table structure:

CREATE TABLE Suppliers(ID INTEGER PRIMARY KEY AUTOINCREMENT,Name varchar(50),Number varchar(15),URL varchar(70),Status bool,ShippingCost integer)

I am then calling a query from QT as follows:

int SQLiteController::ActiveSupplierCount()
{
    int count = 0;
    QSqlQuery Query;
    Query.prepare("SELECT *"
                  "FROM Suppliers"
                  "WHERE Status = (:Status)");
    Query.bindValue(":Status", true);
    Query.exec();
    qDebug() << Query.lastError();
    while(Query.next() == true)
    {
        count  ;
    }
    qDebug() << count;
    return count;
};

The last error returned here is "Parameter count mismatch" and I cannot figure out why... There is only 1 parameter, and I assign to that 1 parameter.

CodePudding user response:

Try to add some extra spaces after each line of your query like this

Query.prepare("SELECT * "
              "FROM Suppliers "
              "WHERE Status = (:Status)");
  • Related