Changeset 13 in mp3-find


Ignore:
Timestamp:
03/24/06 00:15:31 (18 years ago)
Author:
peter
Message:
  • added mp3db to EXE_FILES in Makefile.PL
  • added "sync_db" method to DB.pm; removes outdated records from the database
  • increased version number to '0.03' in Find.pm
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Changes

    r12 r13  
    330.03 
    44    - added "exclude_path" option to filesystem backend 
     5    - added "sync_db" method to the DB backend 
    56 
    670.02  1 Feb 2006 
  • trunk/Makefile.PL

    r3 r13  
    1212    EXE_FILES => [qw( 
    1313        bin/mp3find 
     14        bin/mp3db 
    1415    )],     
    1516    ($] >= 5.005 ?     ## Add these new keywords supported since 5.005 
  • trunk/lib/MP3/Find.pm

    r10 r13  
    99use Carp; 
    1010 
    11 $VERSION = '0.02'; 
     11$VERSION = '0.03'; 
    1212 
    1313@EXPORT = qw(find_mp3s); 
  • trunk/lib/MP3/Find/DB.pm

    r12 r13  
    147147} 
    148148 
     149sub sync_db { 
     150    my $self = shift; 
     151    my $db_file = shift or croak "Need the name of the databse to sync"; 
     152     
     153    my $dbh = DBI->connect("dbi:SQLite:dbname=$db_file", '', '', {RaiseError => 1}); 
     154    my $select_sth = $dbh->prepare('SELECT FILENAME FROM mp3'); 
     155    my $delete_sth = $dbh->prepare('DELETE FROM mp3 WHERE FILENAME = ?'); 
     156     
     157    # the number of records removed 
     158    my $count = 0; 
     159     
     160    $select_sth->execute; 
     161    while (my ($filename) = $select_sth->fetchrow_array) { 
     162        unless (-e $filename) { 
     163            $delete_sth->execute($filename); 
     164            print STDERR "D $filename\n"; 
     165            $count++; 
     166        } 
     167    } 
     168     
     169    return $count;     
     170} 
     171 
    149172sub destroy_db { 
    150173    my $self = shift; 
     
    259282sinc ethe last time C<update_db> was run. 
    260283 
     284=head2 sync_db 
     285 
     286    my $count = $finder->sync_db($db_filename); 
     287 
     288Removes entries from the database that refer to files that no longer 
     289exist in the filesystem. Returns the count of how many records were 
     290removed. 
     291 
    261292=head2 destroy_db 
    262293 
     
    270301 
    271302Allow the passing of a DSN or an already created C<$dbh> instead 
    272 of a SQLite database filename. 
     303of a SQLite database filename; or write driver classes to handle 
     304database dependent tasks (create_db/destroy_db). 
    273305 
    274306=head1 SEE ALSO 
Note: See TracChangeset for help on using the changeset viewer.