diff options
author | Christian Pointner <equinox@helsinki.at> | 2014-09-18 15:23:44 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2014-09-18 15:23:44 (GMT) |
commit | 774a273efbbef7c3416a6e470661e477bda43e1e (patch) | |
tree | 031bc7634413c4957757afd2a2ea0007bae82e5b /lib | |
parent | 7d5dcb875fb6e2d0b0a667d8f93ba401b53b8df1 (diff) |
added functions for number of carts per group
Diffstat (limited to 'lib')
-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; |