summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2015-01-19 19:08:09 +0100
committercos <cos>2015-01-25 22:32:38 +0100
commit3088815bb6cb75b9bd84d1df79808eca43318cf2 (patch)
treefab14b7b0ebe5a4451dba3341a9f1ecb12788420
parentaf1f5c05b22ed3a823561656c534b409b0343636 (diff)
downloadmat-3088815bb6cb75b9bd84d1df79808eca43318cf2.zip
Implement cmd_queuerm.
-rwxr-xr-xmat18
1 files changed, 15 insertions, 3 deletions
diff --git a/mat b/mat
index 4aa61be..b23abe2 100755
--- a/mat
+++ b/mat
@@ -16,7 +16,7 @@ tie my %Config, "Config::Simple", '/etc/mat.conf';
#use Data::Dumper;
-my $db = DBI->connect("dbi:SQLite:recipe.db", "", "", {RaiseError => 1,
+my $db = DBI->connect($Config{'database'}, "", "", {RaiseError => 1,
AutoCommit => 1});
my @recipes;
@@ -469,7 +469,7 @@ sub cmd_help() {
print "shoppinglist <days_to_shop_for>\n";
print "queueshow\n";
print "queueadd <recipe_id> <servings>\n";
- print "queuerm (Yet to be implemented)\n";
+ print "queuerm <queue_id>\n";
print "queuemv (Yet to be implemented)\n";
}
@@ -667,7 +667,19 @@ sub cmd_queueshow {
}
sub cmd_queuerm {
- print "Yet to be implemented!\n";
+ my ( $queue_id ) = @_;
+
+ my $sql = "DELETE FROM queue WHERE id=$queue_id;";
+ my $sth = $db->prepare($sql);
+ my $rv = $sth->execute;
+
+ my $id = $queue_id;
+ do {
+ my $next = $id + 1;
+ $sql = "UPDATE queue SET id=$id WHERE id=$next;";
+
+ $id++;
+ } while($db->do($sql) == 1);
}
sub cmd_queuemv {