diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-09-25 16:07:13 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-09-25 16:07:13 (GMT) |
commit | b8b6d19d27ba5847ef9d93cd1d13f724a850b020 (patch) | |
tree | df1cde17de5b4ffd887fbbe611ddc2ae8cdb3a41 | |
parent | 5ad1a16fbdfaf12199db58be34eb0a8f8942a841 (diff) |
added search for next free cart slot
-rw-r--r-- | README | 2 | ||||
-rwxr-xr-x | lib/RHRD/rddb.pm | 61 | ||||
-rwxr-xr-x | test/get-range | 29 |
3 files changed, 89 insertions, 3 deletions
@@ -10,7 +10,7 @@ CART RANGES: 0 --+----------+ | 2000 | System Macros 2000 --+----------+ - | 1000 | Jingles + | 1000 | Jingles (2 Carts each) 3000 --+----------+ | | | 7000 | <unused> diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index 6e83a5e..a052080 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -41,6 +41,7 @@ use constant { RHRD_SHOW_MACROS_GROUP => 'SHOWS', RHRD_ALLSHOWS_GROUP => 'ALL_SHOWS', RHRD_ALLMUSICPOOLS_GROUP => 'ALL_POOLS', + RHRD_ALLJINGLES_GROUP => 'ALL_JINGLE', }; ########################### connection handling ########################### @@ -107,6 +108,38 @@ sub get_cart_range return ($low_cart, $high_cart, $chunk_size); } +sub get_next_free_slot +{ + my ($dbh, $groupname) = @_; + + my ($group_low_cart, $group_high_cart, $group_chunksize) = get_cart_range($dbh, $groupname); + + my $sql = qq{select NAME, DEFAULT_LOW_CART, DEFAULT_HIGH_CART from GROUPS where NAME != ? and DEFAULT_LOW_CART >= ? and DEFAULT_HIGH_CART <= ? order by DEFAULT_LOW_CART;}; + my $sth = $dbh->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + + $sth->execute($groupname, $group_low_cart, $group_high_cart) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + my ($low_cart, $high_cart) = ($group_low_cart, $group_low_cart + $group_chunksize - 1); + while(my ($slot_name, $slot_low_cart, $slot_high_cart) = $sth->fetchrow_array) { + my $slot_chunksize = $slot_high_cart - $slot_low_cart + 1; + # print " --> " . $slot_name . ": " . $slot_low_cart . " - " . $slot_high_cart . " (" . $slot_chunksize . ")\n";; + if($slot_chunksize != $group_chunksize) { + $sth->finish(); + return (undef, 'ERROR', "show group " . $slot_name . " has wrong chunksize " . $slot_chunksize . " != " . $group_chunksize); + } + + if($high_cart < $slot_low_cart) { + last; # found a hole... + } + ($low_cart, $high_cart) = ($slot_high_cart + 1, $slot_high_cart + $group_chunksize); + } + $sth->finish(); + + return ($low_cart, $high_cart); +} + ########################### TOKEN handling ########################### sub get_token @@ -635,12 +668,38 @@ sub get_shows_cart_range return get_cart_range($dbh, RHRD_ALLSHOWS_GROUP) } +sub get_shows_next_free_slot +{ + my ($dbh) = @_; + return get_next_free_slot($dbh, RHRD_ALLSHOWS_GROUP) +} + ########################### MUSICPOOL handling ########################### -sub get_musicpool_cart_range +sub get_musicpools_cart_range { my ($dbh) = @_; return get_cart_range($dbh, RHRD_ALLMUSICPOOLS_GROUP) } +sub get_musicpools_next_free_slot +{ + my ($dbh) = @_; + return get_next_free_slot($dbh, RHRD_ALLMUSICPOOLS_GROUP) +} + +########################### JINGLES handling ########################### + +sub get_jingles_cart_range +{ + my ($dbh) = @_; + return get_cart_range($dbh, RHRD_ALLJINGLES_GROUP) +} + +sub get_jingles_next_free_slot +{ + my ($dbh) = @_; + return get_next_free_slot($dbh, RHRD_ALLJINGLES_GROUP) +} + ################################# END #################################### diff --git a/test/get-range b/test/get-range index 13e5533..1d4e12e 100755 --- a/test/get-range +++ b/test/get-range @@ -34,14 +34,41 @@ if(defined $dbh) { } else { print "Range: " . $low_cart . " - " . $high_cart . ", chunk size: " . $chunk_size . "\n"; } + my ($slot_low_cart, $slot_high_cart, $err) = RHRD::rddb::get_shows_next_free_slot($dbh); + if(!$slot_low_cart) { + print "$slot_high_cart: $err\n"; + } else { + print " Next Free: " . $slot_low_cart . " - " . $slot_high_cart . "\n"; + } print "\nMusic Pools:\n"; - ($low_cart, $high_cart, $chunk_size) = RHRD::rddb::get_musicpool_cart_range($dbh); + ($low_cart, $high_cart, $chunk_size) = RHRD::rddb::get_musicpools_cart_range($dbh); if(!$low_cart) { print "$high_cart: $chunk_size\n"; } else { print "Range: " . $low_cart . " - " . $high_cart . ", chunk size: " . $chunk_size . "\n"; } + ($slot_low_cart, $slot_high_cart, $err) = RHRD::rddb::get_musicpools_next_free_slot($dbh); + if(!$slot_low_cart) { + print "$slot_high_cart: $err\n"; + } else { + print " Next Free: " . $slot_low_cart . " - " . $slot_high_cart . "\n"; + } + + print "\nJingles:\n"; + ($low_cart, $high_cart, $chunk_size) = RHRD::rddb::get_jingles_cart_range($dbh); + if(!$low_cart) { + print "$high_cart: $chunk_size\n"; + } else { + print "Range: " . $low_cart . " - " . $high_cart . ", chunk size: " . $chunk_size . "\n"; + } + ($slot_low_cart, $slot_high_cart, $err) = RHRD::rddb::get_jingles_next_free_slot($dbh); + if(!$slot_low_cart) { + print "$slot_high_cart: $err\n"; + } else { + print " Next Free: " . $slot_low_cart . " - " . $slot_high_cart . "\n"; + } + RHRD::rddb::closedb($dbh); } else { |