diff options
-rwxr-xr-x | mat | 9 |
1 files changed, 2 insertions, 7 deletions
@@ -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); |