0

I am writing a Qt5/c++ app using QSqlDatabase with SQLite. I need to nest an update query inside a loop that iterates over a read query result set, as described in pseudo code here:

readQuery.exec();
while(readQuery.next()) {
    if (readQuery.value("col1").toString() == "test") {
        QSqlQuery updateQuery;
        updateQuery.prepare("UPDATE table SET val=:val WHERE key=:key");
        updateQuery.bindValue(":val", someval);
        updateQuery.bindValue(":key", somekey);
        updateQuery.exec();
     }
}
  

Both queries act on the same table. Is this safe to do? Will the update query mess up the results from my read query?

TSG
  • 4,242
  • 9
  • 61
  • 121

0 Answers0