Changeset 13 in mp3-find for trunk/lib/MP3/Find


Ignore:
Timestamp:
03/24/06 00:15:31 (19 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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.