New code where I check return status (I believe I found them all):
sqlWhere.append("recipecode='");
sqlWhere.append(cboRecipeSelect->currentText());
sqlWhere.append( "' AND isactive=true");
recipeTable.setTable("recipe");
recipeTable.setFilter(sqlWhere);
bool boolSelect = recipeTable.select();
qDebug () << "recipe select a record returned " << boolSelect;
int rowcount = recipeTable.rowCount();
qDebug () << "the select returned " << rowcount << " rows";
if (!recRecipe.isEmpty()) // backwards way to say record exists
{
// if we get this far, it's an update
recRecipe.setValue("isactive",false);
// recipeUpTable.setData(recipeUpTable.index(0,2), false);
bool boolRecSubmit = recipeTable.submitAll(); // and update the existing record
qDebug () << "value for isactive is " << recRecipe.value("isactive");
qDebug () << "submitAll call return value " << boolRecSubmit;
qDebug () << "submitAll error message " <<recipeTable.lastError().text();
//
}
sqlWhere.append("recipecode='");
sqlWhere.append(cboRecipeSelect->currentText());
sqlWhere.append( "' AND isactive=true");
QSqlTableModel recipeTable;
recipeTable.setTable("recipe");
recipeTable.setFilter(sqlWhere);
bool boolSelect = recipeTable.select();
qDebug () << "recipe select a record returned " << boolSelect;
int rowcount = recipeTable.rowCount();
qDebug () << "the select returned " << rowcount << " rows";
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);
// recipeUpTable.setData(recipeUpTable.index(0,2), false);
bool boolRecSubmit = recipeTable.submitAll(); // and update the existing record
qDebug () << "value for isactive is " << recRecipe.value("isactive");
qDebug () << "submitAll call return value " << boolRecSubmit;
qDebug () << "submitAll error message " <<recipeTable.lastError().text();
//
}
To copy to clipboard, switch view to plain text mode
Qt Creator Application Output:
recipe select a record returned true
the select returned 1 rows
value for isactive is QVariant(bool, false)
submitAll call return value true
submitAll error message " "
Still have two active recipes in the database recipe table.
I'm missing something somewhere ...
Bookmarks