- my $ref = $dbh->selectrow_hashref('SELECT * FROM songs ORDER BY random() LIMIT 1');
+ my $ref = $dbh->selectrow_hashref('SELECT * FROM machinesongs WHERE song NOT IN ( SELECT song FROM randomsongsused ) AND machine=( SELECT machine FROM tournaments WHERE tournament=? ) ORDER BY random() LIMIT 1',
+ undef, $tournament);
+ if (!defined($ref)) {
+ ccbs::user_error('Det er ikke flere sanger igjen i sangvelgeren!');
+ }
+ $dbh->do('INSERT INTO randomsongsused (song) VALUES (?)',
+ undef, $ref->{'song'});
$dbh->do('INSERT INTO roundrandomsongs (tournament, round, parallel, song) VALUES (?,?,?,?)',
undef, $tournament, $round, $g, $ref->{'song'});
$dbh->do('INSERT INTO roundrandomsongs (tournament, round, parallel, song) VALUES (?,?,?,?)',
undef, $tournament, $round, $g, $ref->{'song'});