diff options
-rwxr-xr-x | lib/rddb.pm | 33 |
1 files changed, 33 insertions, 0 deletions
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; |