I’m trying to delete with qt with this code:
int jobId = 655;
query.prepare("DELETE FROM jobs WHERE jobId = '" + QString::number(jobId) + "'");
QString error = query.lastError().text();
if (query.exec())
qDebug() << "DELETE ok";
else
qDebug() << error;
if jobId exist all fine but if not exit too show “DELETE ok”.
How can I check this situation?.
Thanks you very much
A
DELETEquery doesn’t generate error if it has nothing to delete.You might be able to find if something was deleted with
QSqlQuery::numRowsAffected.But if you want to know if the id exists before deleting it, you have to do a separate
SELECTrequest for that id.PS: you should use
addBindValueorbindValueto insert values in the query string: