QSqlQuery with prepare and bindValue for column name Sqlite

后端 未结 1 862
时光说笑
时光说笑 2021-01-05 06:43
void updateDB(const int id, const QString& column, const QVariant& value) const 
 //*****
 //all stuff on open DB etc. 
QSqlQuery query;
query.prepare(\"UPDA         


        
相关标签:
1条回答
  • 2021-01-05 07:12

    Correct code here would be:

    query.prepare(QString("UPDATE table SET %1 = :value WHERE id = :id ").arg(column));
    query.bindValue(":value", value);
    

    You bind values, not fields names.

    P.S.: answered before reading whole question. Yes, you are right - there is no way to use bindValues to bind columns, not only for sqlite, but for each db.

    0 讨论(0)
提交回复
热议问题