Parameter count mismatch on SELECT statement - SQLITE



  • Hi, I'm currently facing an error where I get "Parameter count mismatch" from query.lastError, my bindvalues are correct (i've tested them).

    My query is:

    QSqlQuery query(DBT);
        query.prepare("SELECT Foto, Nombre, Apellido1, Apellido2, Curso, Grupo, FotoHuella FROM usuarios WHERE Nombre=:nombre1 OR Apellido1=:apellido1 OR Apellido2=:apellido2 OR Curso=:curso1 OR Grupo=:grupo1");
            query.bindValue(":nombre1", nombre, QSql::Out);
            query.bindValue(":apellido1", apellido1, QSql::Out);
            query.bindValue(":apellido2", apellido2, QSql::Out);
            query.bindValue(":curso1", curso, QSql::Out);
            query.bindValue(":grupo1", grupo, QSql::Out);
        query.exec();
    

    In case you where wondering here is where I set up the database:

        QSqlDatabase DBT=QSqlDatabase::addDatabase("QSQLITE");
        DBT.setDatabaseName("/home/pi/FoodCircleDBT.db");
        DBT.open();
    

    Thanks in advance.



  • Hi @cxam,

    The problem is that you're specifying QSql::Out - this should be QSql::In which is the default value in the function signature anyway, so you can just leave off the QSql::Out parameter.

    Perhaps the reason you thought to use QSql::Out is that your query is getting (SELECTing) data out of the database, which it is. But the binding itself is providing values into the database query, and so its an input (from the query's perspective), not an output. I hope that makes sense.

    Cheers.



  • Oh you are right! Thanks a lot!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.