Qt SQlite Parameter count mismatch



  • Hi

    I Have a project in Qt and SQlite as a database. In this code, I use queryBindValue and the exec() returns "Parameter count mismatch" But I have only one parameter.

    This code works fine in Ubuntu, but fails in Windows and in chackra Linux.

    Help-me please I'm a beginner in Qt.

    Lot of thanks

    Here the code:

    @ // Conexión SQLite
    QSqlDatabase dbTerra = QSqlDatabase::addDatabase("QSQLITE","terra");
    dbTerra.setDatabaseName("/home/arcnexus/project/terra/terra/DB/terra.sqlite");
    dbTerra.open();
    if (dbTerra.lastError().isValid())
    {
    QMessageBox::critical(0, "error:", dbTerra.lastError().text());

        }@
    

    @ QSqlQuery qryUsers(QSqlDatabase::database("terra"));
    qryUsers.prepare( "SELECT * FROM usuarios where nombre =:Nombre" );

    qryUsers.bindValue(":Nombre",ui->lineUsuario->text());
    
    if( !qryUsers.exec() ) {
    
        QMessageBox::critical(NULL, "error:", qryUsers.lastError().text());
    } else {
        if (qryUsers.next()) {
            if (ui->linePassword->text()==qryUsers.value(2).toString()) {
    
                Login::done( QDialog::Accepted);
    
            } else {
                QMessageBox::critical(0,"ACCESO DENEGADO","El usuario y la contraseña no se corresponden\n\n Verifique los datos");
                ui->linePassword->setText("");
                ui->linePassword->setFocus();
            }@


  • Try using another placeholder i mean use something like :nbre instead of :nombre and see what you get.



  • Instead of

    @ QSqlQuery qryUsers(QSqlDatabase::database("terra"));
    qryUsers.prepare( "SELECT * FROM usuarios where nombre =:Nombre" );

    qryUsers.bindValue(":Nombre",ui->lineUsuario->text());
    
    if( !qryUsers.exec() ) {
    

    @

    try

    @
    QSqlQuery qryUsers(QSqlDatabase::database("terra"));

    const QString &str =
    QString( "SELECT * FROM usuarios where nombre =%1" )
    .arg(ui->lineUsuario->text());

    if( !qryUsers.exec( str ) ) {
    ...
    @

    In my experience the query.prepare with placeholders only works when using INSERT or UPDATE statements.



  • Hi franku
    thanks for your answer.

    I test it.

    Anyway I deleted the folder where is the compiled code and recompile. Now the same code works very well in chakra. I have to test on Windows.

    I think it was a permisions problem. But, I prove your solution.



  • [quote author="Neutron Stein" date="1343464077"]Try using another placeholder i mean use something like :nbre instead of :nombre and see what you get.[/quote]

    I test it and obtain de same error

    thanks for answer.


Log in to reply
 

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