diff options
author | cos <cos> | 2015-01-19 19:08:09 +0100 |
---|---|---|
committer | cos <cos> | 2015-01-25 22:32:38 +0100 |
commit | 3088815bb6cb75b9bd84d1df79808eca43318cf2 (patch) | |
tree | fab14b7b0ebe5a4451dba3341a9f1ecb12788420 | |
parent | af1f5c05b22ed3a823561656c534b409b0343636 (diff) | |
download | mat-3088815bb6cb75b9bd84d1df79808eca43318cf2.zip |
Implement cmd_queuerm.
-rwxr-xr-x | mat | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -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 { |