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. Add new data to SQLite table

Add new data to SQLite table

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 1.8k 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.
  • JulianJ Offline
    JulianJ Offline
    Julian
    wrote on last edited by
    #1

    There is an existing database with information. How do you add a new row?

    What I did it's:

    
    
        QString texto;
        texto=ui->lineEdit_interseccion->text();
    
        QString texto2;
        texto2=ui->lineEdit_interseccion->text().remove(" ", Qt::CaseInsensitive);
        QDate nuevo;
        QString a1;
        a1.append("INSERT INTO ");
        a1.push_back(texto2);
    
        a1.push_back(" (a,b) VALUES(:a,:b);");
    
        QSqlQuery insert(fallas);
        if(!insert.prepare(a1))
        {
            qDebug()<<":::::::"<<insert.lastQuery()<<endl;
        }
    
    
        insert.bindValue(":a", nuevo.currentDate().toString(Qt::RFC2822Date));
        insert.bindValue(":b", ui->textEdit->toPlainText());
    
    
         if(!insert.exec())
         {
             qDebug()<<"...."<<insert.lastError()<<endl;
         }
    
    

    The error it's in exec and it's :

    .... QSqlError("19", "Unable to fetch row", "UNIQUE constraint failed: ayb.a")

    by the way ayb it's the database name. and the prepare argument is INSERT INTO ayb (a,b) VALUES(:a,:b);

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on last edited by
      #2

      Hi @Julian

      I think that the error :

      "UNIQUE constraint failed: ayb.a"

      Means that you have already a row that contain the value that you want to answer

      You can start by checking which values are inserted on column a

      Hope this can help !

      1 Reply Last reply
      2
      • A Offline
        A Offline
        adeptsol
        Banned
        wrote on last edited by tekojo
        #3
        This post is deleted!
        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