Fix multiple insert a new recipe.

Wed, 27 Apr 2022 10:38:05 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 27 Apr 2022 10:38:05 +0200
changeset 165
c8e6ab63d671
parent 164
47ee0d1b47e9
child 166
60ea10dcc0e4

Fix multiple insert a new recipe.

src/EditRecipe.cpp file | annotate | diff | comparison | revisions
--- a/src/EditRecipe.cpp	Wed Apr 27 09:12:41 2022 +0200
+++ b/src/EditRecipe.cpp	Wed Apr 27 10:38:05 2022 +0200
@@ -1093,7 +1093,18 @@
                         .arg(query.lastError().driverText())
                         .arg(query.lastError().databaseText()));
 	} else {
-	    qDebug() << "EditRecipe Saved";
+	    /*
+	     * If this was a new recipe, find out what record number we
+	     * have got and set it. So when the user saves this record
+	     * again, it will be updated instead of inserting a new copy.
+	     */
+	    if (this->recno < 0) {
+		QVariant id = query.lastInsertId();
+		this->recno = recipe->record = id.toInt();
+		qDebug() << "EditRecipe Inserted record" << this->recno;
+	    } else {
+		qDebug() << "EditRecipe Updated record" << this->recno;
+	    }
 	}
     }
 

mercurial