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. Qt SQlite Parameter count mismatch

Qt SQlite Parameter count mismatch

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 6.4k Views 1 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.
  • A Offline
    A Offline
    ArcNexus
    wrote on last edited by
    #1

    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();
            }@
    

    When we are one, we win

    1 Reply Last reply
    0
    • N Offline
      N Offline
      Neutron Stein
      wrote on last edited by
      #2

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

      Never Seen !

      1 Reply Last reply
      0
      • F Offline
        F Offline
        franku
        wrote on last edited by
        #3

        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.

        This, Jen, is the internet.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ArcNexus
          wrote on last edited by
          #4

          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.

          When we are one, we win

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ArcNexus
            wrote on last edited by
            #5

            [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.

            When we are one, we win

            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