Take the tour ×  I wrote a database update program. The problem
is that value is the QString, which may include ' in some cases.
It must not be removed. Here is the code:  QSqlQuery q; q =
db.exec("UPDATE " + arr + " SET " + name + " = '" + value + "'
WHERE question_id = "+ id);  any ideas?  share|improve this
question add comment  2 Answers  up vote 0 down vote accepted
You have to use parameters (or placeholders):  QSqlQuery q =
QSqlQuery(db); q.prepare("UPDATE " + arr + " SET " + name + " =
:name WHERE question_id = :id"); q.bindValue(":name", value);
q.bindValue(":id", id);  It is better to always use parameters
to pass any value to your queries. Appending values to query
string, is subject to sql injection attack, and also may not
always work (as in your situation).  share|improve this answer
add comment  The ' must be escaped by doubling it. Use the
driver to do it as shown in the MD.Unicorn's answer.
share|improve this answer add comment  Your Answer