summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2011-08-08 18:44:20 +0200
committercos <cos>2011-08-08 18:44:20 +0200
commitfbff367b5e3177507b83d721265b6222a12ad051 (patch)
tree650cb1cfc616a99b9fd41cbd4933f757a5823599
parent57817436298c107fb7727dd292185ebff21d8d66 (diff)
downloadmat-fbff367b5e3177507b83d721265b6222a12ad051.zip
Changed setmeal to overwrite existing meals.
-rwxr-xr-xmat9
1 files 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);