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. No query Unable to fetch row issue.
Forum Updated to NodeBB v4.3 + New Features

No query Unable to fetch row issue.

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 4.6k 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.
  • M Offline
    M Offline
    MadScientist92
    wrote on last edited by MadScientist92
    #1

    I have written a piece of code that loads sqlite database into qtableview. Than I've successfully implemented SELECT statement ```

     QModelIndex index = ui->tableView->selectionModel()->currentIndex();
     QString value= ui->tableView->model()->data(index).toString();
     qDebug() << "Value : " << value;
    
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("TestDatabase.db");
    
    if(!db.open())
    {
        qDebug() << db.lastError();
        qFatal("Failed to connect");
    }
    QSqlQuery qry;
    qry.prepare("SELECT * FROM movies WHERE Title='"+value+"'");
    
    if(qry.exec())
    {
        while(qry.next())
        {
            ui->titleEdit->setText(qry.value(0).toString());
        }
    

    However, when I try to delete record from database the same way it throws me 'No query Unable to fetch row'.

     QModelIndex index = ui->tableView->selectionModel()->currentIndex();
    
        QString value= ui->tableView->model()->data(index).toString();
        qDebug() << "Value : " << value;
    
        QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
        db.setDatabaseName("TestDatabase.db");
    
        if(!db.open())
        {
            qDebug() << db.lastError();
            qFatal("Failed to connect");
        }
        QSqlQuery qry;
        qry.prepare("DELETE * FROM movies WHERE Title='"+value+"'");
        qry.bindValue(":Title" , value);
         if(!qry.exec())
         {
            QMessageBox::critical(this, tr("error::") , qry.lastError().text());
    
         }
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      hi
      You have
      qry.bindValue(":Title" , value);
      but not using the binding syntax ?
      ( in delete example)

      Also, if you look here
      http://www.sqlitetutorial.net/sqlite-delete/
      alt text

      To use "Title =" , you must be 100% sure its a 100% match.
      Big/small letters and all.

      You can use
      http://sqlitebrowser.org/

      to test out your sql.

      1 Reply Last reply
      4
      • M Offline
        M Offline
        MadScientist92
        wrote on last edited by
        #3

        I was trying to do the same thing using bind, but it was giving me 'Parameter count mismatch'. I am sure that it is 100% match, because these values are taken from the very same table.

        mrjjM 1 Reply Last reply
        0
        • M MadScientist92

          I was trying to do the same thing using bind, but it was giving me 'Parameter count mismatch'. I am sure that it is 100% match, because these values are taken from the very same table.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @MadScientist92
          Did u try in DB browser ?
          Then u know for sure if its your code or not.

          1 Reply Last reply
          2
          • M Offline
            M Offline
            MadScientist92
            wrote on last edited by
            #5

            Thank you very much for the tip. I've tried to run it in db browser and it turned out I didn't have to place '*' after DELETE.

            mrjjM 1 Reply Last reply
            1
            • M MadScientist92

              Thank you very much for the tip. I've tried to run it in db browser and it turned out I didn't have to place '*' after DELETE.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @MadScientist92
              oh, i completely missed that :(
              even posted picture without *
              (erhm)
              Super

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved