X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=lib%2FApp%2FMPD%2FFeeder%2FDB.pm;h=5ba1dde2c8a87e35634a2f7dc4abaafc7fc9fd08;hb=e72d5851c56146ac78be91b720ed7d7451fcc0d0;hp=62164364e167f6415d4c0538d0443cd2b8240687;hpb=02b8ebf94e41430d2c90b39e3348fc647522f697;p=mpd-feeder.git diff --git a/lib/App/MPD/Feeder/DB.pm b/lib/App/MPD/Feeder/DB.pm index 6216436..5ba1dde 100644 --- a/lib/App/MPD/Feeder/DB.pm +++ b/lib/App/MPD/Feeder/DB.pm @@ -293,6 +293,59 @@ SQL return $count; } + method add_unwanted_album($album, $artist) { + $self->connect; + + try { + $db->do( + <<'SQL', +INSERT INTO unwanted_albums(album, artist, generation) +VALUES($1, $2, $3) +SQL + undef, $album, $artist, $generation + ); + return 1; + } + catch { + my $err = $@; + + $log->debug("PostgreSQL error: $err"); + $log->debug( "SQLSTATE = " . $db->state ); + return 0 if $db->state eq '23505'; + + die $err; + } + } + + method del_unwanted_album($album, $artist) { + $self->connect; + + return 1 == $db->do( + <<'SQL', +DELETE FROM unwanted_albums +WHERE album = $1 AND artist = $2 +SQL + undef, $album, $artist + ); + } + + method walk_unwanted_albums($callback) { + $self->connect; + + my $count = 0; + + my $sth = $db->prepare('SELECT album, artist FROM unwanted_albums ORDER BY 2, 1'); + my ( $album, $artist ); + $sth->execute; + $sth->bind_columns( \$album, \$artist ); + while ( $sth->fetchrow_arrayref ) { + $count++; + $callback->($album, $artist); + } + + return $count; + } + method disconnect { return unless $db;