From 774a273efbbef7c3416a6e470661e477bda43e1e Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 18 Sep 2014 15:23:44 +0000 Subject: added functions for number of carts per group diff --git a/lib/rddb.pm b/lib/rddb.pm index 2881fb1..017003b 100755 --- a/lib/rddb.pm +++ b/lib/rddb.pm @@ -74,4 +74,37 @@ sub check_token return (0, 'ERROR', "wrong password"); } +sub get_cart_range +{ + my ($dbh, $group) = @_; + + my $sql = qq{select DEFAULT_LOW_CART,DEFAULT_HIGH_CART from GROUPS where NAME = ?;}; + my $sth = $dbh->prepare($sql) + or return (undef, undef, 'ERROR', "Database Error: " . $dbh->errstr); + + $sth->execute($group) + or return (undef, undef, 'ERROR', "Database Error: " . $sth->errstr); + + my ($low_cart, $high_cart) = $sth->fetchrow_array(); + $sth->finish(); + + unless(defined $low_cart && defined $high_cart) { + return (undef, undef, 'ERROR', "group '" . $group . "' not known by rivendell") + } + return ($low_cart, $high_cart, 'OK', 'success'); +} + +sub get_num_carts +{ + my ($dbh, $group) = @_; + + my ($low_cart, $high_cart, $status, $errorstring) = get_cart_range($dbh, $group); + unless(defined $low_cart && defined $high_cart) { + return (undef, $status, $errorstring); + } + + return ($high_cart - $low_cart + 1, 'OK', 'success'); +} + + return 1; -- cgit v0.10.2