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. Could not insert new data in sqlite db

Could not insert new data in sqlite db

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 945 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
    mark_ua_1999
    wrote on last edited by mark_ua_1999
    #1

    Hi I am trying to insert data in db the connection is set but i get masseges( QSqlQuery::prepare: no driver, no query could not fetch the row ) how could i resolve it thanks
    QSqlQuery r;
    QSqlDatabase db1 = QSqlDatabase::addDatabase("QSQLITE");
    db1.setDatabaseName("C:\SQLiteDatabaseBrowserPortable\Data\cities.db");
    db1.open();
    if(db1.isOpen())
    {
    QProgressBar l = ui->tableWidget->cellWidget(ui->tableWidget->rowCount()-1,5)->findChild<QProgressBar>();
    l->setMinimum(0);
    l->setMaximum(train_.passangers.size());
    l->setValue(0);
    this->setCursor(Qt::WaitCursor);
    QApplication::processEvents();

           for(int i = 0; i< train_.passangers.size();i++)
           {
                    l->setValue(i+1);
              // r.clear();
      if(r.prepare("INSERT INTO "+name+" (depart_city,arrival_city,firstname,lastname,bot,vagon,place,privileges,distance,ticket_price,depart_time,arrival_time)"
        "VALUES (:depart_city,:arrival_city,:first_name,:lastname,:bot,:vagon,:place,:privileges,:distance,:ticket_price,:depart_time,:arrival_time)"))
          ui->textBrowser->append("Yes");
      else
          ui->textBrowser->append("--"+r.lastError().text());
        r.bindValue(":depart_city",train_.passangers[i].left_city);
                          r.bindValue(":arrival_city",train_.passangers[i].arrival_city);
                          r.bindValue(":first_name",train_.passangers[i].name);
                         r.bindValue(":lastname",train_.passangers[i].surname);
                          r.bindValue(":bot","yes");
                         r.bindValue(":vagon",train_.passangers[i].wagon);
                          r.bindValue(":place",train_.passangers[i].place);
                          r.bindValue(":privileges","no");
                          r.bindValue(":distance",train_.passangers[i].way_distance);
                          r.bindValue(":ticket_price",train_.passangers[i].ticket_cost);
                          r.bindValue(":depart_time",train_.passangers[i].left_time_);
                          r.bindValue(":arrival_time",train_.passangers[i].arrival_time_);
    
                         if(r.exec())
                             ui->textBrowser->append("Yes");
                         else
                             ui->textBrowser->append(r.lastError().text());
                          QCoreApplication::processEvents();
           }
    
                  this->setCursor(Qt::ArrowCursor);
          }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You creare the r object before there's any database connection available.

      Like it was already suggested several times: setup your database once at application startup, that will simplify your life.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        You creare the r object before there's any database connection available.

        Like it was already suggested several times: setup your database once at application startup, that will simplify your life.

        M Offline
        M Offline
        mark_ua_1999
        wrote on last edited by
        #3

        @SGaist thanks

        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