Important: Please read the Qt Code of Conduct -

Add new data to SQLite table

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

    What I did it's:

        QString texto;
        QString texto2;
        texto2=ui->lineEdit_interseccion->text().remove(" ", Qt::CaseInsensitive);
        QDate nuevo;
        QString a1;
        a1.append("INSERT INTO ");
        a1.push_back(" (a,b) VALUES(:a,:b);");
        QSqlQuery insert(fallas);
        insert.bindValue(":a", nuevo.currentDate().toString(Qt::RFC2822Date));
        insert.bindValue(":b", ui->textEdit->toPlainText());

    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);

  • 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 !

  • Banned

    This post is deleted!

Log in to reply