I have a table that contains recipe records. The application has been around since 2004. Now moving it into Qt5. I'm having issues updating a field in an existing record. When the operator wants to save a new recipe with the same recipe code. I need to set the current recipe "isactive" boolean false. This has worked fine until now. The Qt4 code looks like ...
sqlWhere.append("recipecode='");
sqlWhere.append(cboRecipeSelect->currentText());
sqlWhere.append( "' AND isactive=true");
recipeTable.setTable("recipe");
recipeTable.setFilter(sqlWhere);
recipeTable.select();
if (!recRecipe.isEmpty()) // backwards way to say record exists
{
// if we get this far, it's an update
recRecipe.setValue("isactive",false);
recipeTable.setRecord(0,recRecipe);
recipeTable.submitAll(); // and update the existing record
qDebug () << "updating recipe record to not active " <<recipeTable.lastError().text();
QString sqlWhere;
sqlWhere.append("recipecode='");
sqlWhere.append(cboRecipeSelect->currentText());
sqlWhere.append( "' AND isactive=true");
QSqlTableModel recipeTable;
recipeTable.setTable("recipe");
recipeTable.setFilter(sqlWhere);
recipeTable.select();
QSqlRecord recRecipe = recipeTable.record(0);
if (!recRecipe.isEmpty()) // backwards way to say record exists
{
// if we get this far, it's an update
recRecipe.setValue("isactive",false);
recipeTable.setRecord(0,recRecipe);
recipeTable.submitAll(); // and update the existing record
qDebug () << "updating recipe record to not active " <<recipeTable.lastError().text();
To copy to clipboard, switch view to plain text mode
qDebug shows " ". And the field in the record remains "true".
What am I missing / failing to understand?
Bookmarks