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. [SOLVED] parameter count mismatch sqlite and qt error
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] parameter count mismatch sqlite and qt error

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 10.0k 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
    advseo32
    wrote on last edited by
    #1

    i have error with sqlite query

    i don't know where is the problem the problem exactly

    i have make a default connexion in mainwindow.cpp

    and i just get the default connexion and query the data base, but isn't works

    her is my code so far
    @
    QSqlDatabase db = QSqlDatabase::database() ;

    QSqlQuery query ;

    query.prepare("select seq from sqlite_sequence where name= ? ");

    query.addBindValue("articles");

    if(!query.exec())
    {
    QMessageBox::critical(this,"Inventoria solti",query.lastError().text());
    return ;
    }

    while (query.next())
    {
    ui->lineEdit->setText(query.value(0).toString());
    }@

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      I think you need to pass your "db" to your QSqlQuery query,
      Like this,
      @QSqlQuery query(db);@

      157

      1 Reply Last reply
      0
      • A Offline
        A Offline
        advseo32
        wrote on last edited by
        #3

        i tried this but i get the same error

        i don't know where is the problem every thing is correct , because i use the same code in other example an it works

        @
        QSqlDatabase db = QSqlDatabase::database() ;

        QSqlQuery query(db) ;
        
        QString queryString = "select seq from sqlite_sequence where name= ?";
        
        query.prepare(queryString);
        
        query.addBindValue(str);
        
        if(!query.exec())
        {
            QMessageBox::critical(this,tr("Inventaire"),query.lastError().text());
            return;
        }
        
        while(query.next())
        {
            ui->articleCodeLineEdit->setText("ART_" + QString::number(query.value(0).toInt() + 1));
            return ;
        }
        
        if(ui->articleCodeLineEdit->text().isEmpty())
            ui->articleCodeLineEdit->setText("ART_1");
        

        @

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Hi,
          You can alternatively try this,
          @
          QSqlQuery query(QSqlDatabase::database());
          query.exec(select seq from sqlite_sequence where name='"+str+"');
          while (query.next()) {
          qDebug() << query.value(0).toInt();
          }
          @

          157

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

            i tried your code and i get

            "no such table sqlite_sequence enable to execute statement" error

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              Thats strange the following coe works for me,
              @
              QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
              db.setDatabaseName("/root/test.db");

              bool ret = db.open();

              QSqlQuery query(QSqlDatabase::database());
              QString str = "t1";
              query.exec("select seq from sqlite_sequence where name='"+str+"'");

              while (query.next()) {
              qDebug() << query.value(0).toString();
              }
              @

              157

              1 Reply Last reply
              0
              • A Offline
                A Offline
                advseo32
                wrote on last edited by
                #7

                sorry, p3c0, for the stupide error

                i don't write the path of database correctly

                i have writed

                this path " E:\apprendreQt\gestionstock6\database\inventaire.db"

                instead of "E:/Programing/database/inventaire.db"

                int mainwindow.cpp

                her is the code of connexion

                @ m_db = new QSqlDatabase;
                // Base de données traitement
                *m_db = QSqlDatabase::addDatabase("QSQLITE") ;
                m_db->setHostName("localhost");
                m_db->setDatabaseName("E:/Programing/database/inventaire.db");
                m_db->setPassword("");
                m_db->setUserName("");
                if(!m_db->open())
                QMessageBox::critical(this,"erreur connecting",m_db->lastError().text());

                m_fenetreArticle = new article(this);
                m_fenetreArticle->setWindowFlags(Qt::Window);@
                
                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