From fbff367b5e3177507b83d721265b6222a12ad051 Mon Sep 17 00:00:00 2001 From: cos Date: Mon, 8 Aug 2011 18:44:20 +0200 Subject: Changed setmeal to overwrite existing meals. --- mat | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/mat b/mat index 2a60aa8..d692cd9 100755 --- a/mat +++ b/mat @@ -106,16 +106,11 @@ sub cmd_setmeal { $date = $dt->ymd(); } return unless $date =~ "^[0-9]{4}-[0-9]{2}-[0-9]{2}\$"; - - # FIXME This is a potential race condition. In theory I should be able to do - # rollback if there are more than one entry matching this select at the end - # of the function. Even better: add a constraint to the db if that is - # possible. - my $sql = "SELECT * FROM plan WHERE date='$date' and mealtype='$mealtype';"; - return -1 if ($db->selectrow_array($sql)); return -1 unless $recipe_id =~ "^[0-9]+\$"; if (get_recipe_name($recipe_id) ne 'NULL') { + my $sql = "DELETE FROM plan WHERE date='$date' and mealtype='$mealtype';"; + $db->do($sql); $sql = "INSERT INTO plan (date, mealtype, recipe_id) VALUES ('$date', '$mealtype', $recipe_id);"; $db->do($sql); -- cgit v1.2.3