0

I created a function to add new records to an sqlite table everything works fine but when trying to insert strings two extra quotes are added

code:

int dBase::ajouter(QString table,QVector<QVariant> valeurs)
{
    connect();
    QSqlQuery query(db);


    QString sql="INSERT INTO "+table+" VALUES (NULL";
    for(int i=0;i<valeurs.length();i++)
        sql+=", :val"+QString::number(i);
    sql+=")";

    query.prepare(sql);
    for(int i=0;i<valeurs.length();i++)
        query.bindValue(":val"+QString::number(i), valeurs.at(i));

    int ret=-1;

    if(query.exec())
        ret=query.lastInsertId().toInt();
    else
        qDebug()<<query.lastError();
    disconnect();

    return ret;
}

values as shown when executing select:

1|'Nom'|'Pays'|'Ville'|'Adresse'|1234|'12345678'|'13245678'|'12345678'|'email@email.com'

I discovered this problem when trying to use while Nom="x" it always return no records.

  • These quotes are already in the values in the `valeurs` array, so the database thinks that you actually want to insert them. Which code generates these values? – CL. Dec 09 '14 at 08:33
  • Thank you @CL. , now I feel stupid. I don't know how I didn't check those, I spent hours trying to fix this banal problem – user3281996 Dec 09 '14 at 13:36

0 Answers0