Index: trunk/lib/MP3/Find/DB.pm
===================================================================
--- trunk/lib/MP3/Find/DB.pm	(revision 31)
+++ trunk/lib/MP3/Find/DB.pm	(revision 32)
@@ -15,5 +15,5 @@
 
 my @COLUMNS = (
-    [ mtime        => 'INTEGER' ],  # the filesystem mtime, so we can do incremental updates
+    [ mtime        => 'INTEGER' ],  # filesystem mtime, so we can do incremental updates
     [ FILENAME     => 'TEXT' ], 
     [ TITLE        => 'TEXT' ], 
@@ -397,22 +397,16 @@
 }
 
-=head2 sync_db
-
-    my $count = $finder->sync_db($db_filename);
-
-Removes entries from the database that refer to files that no longer
-exist in the filesystem. Returns the count of how many records were
-removed.
-
-=cut
-
-# TODO: use DSNs instead of SQLite db names
-sub sync_db {
-    my $self = shift;
-    my $db_file = shift or croak "Need the name of the databse to sync";
-
+=head2 sync
+
+=cut
+
+sub sync {
+    my $self = shift;
+    my $args = shift;
+
+    my $dbh = _get_dbh($args) or croak "Please provide a DBI database handle, DSN, or SQLite database filename";
+    
     my $status_callback = $self->{status_callback} || $DEFAULT_STATUS_CALLBACK;
 
-    my $dbh = DBI->connect("dbi:SQLite:dbname=$db_file", '', '', {RaiseError => 1});
     my $select_sth = $dbh->prepare('SELECT FILENAME FROM mp3');
     my $delete_sth = $dbh->prepare('DELETE FROM mp3 WHERE FILENAME = ?');
@@ -433,4 +427,40 @@
 }
 
+=head2 sync_db
+
+    my $count = $finder->sync_db($db_filename);
+
+Removes entries from the database that refer to files that no longer
+exist in the filesystem. Returns the count of how many records were
+removed.
+
+=cut
+
+# TODO: use DSNs instead of SQLite db names
+sub sync_db {
+    my $self = shift;
+    my $db_file = shift or croak "Need the name of the databse to sync";
+
+    my $status_callback = $self->{status_callback} || $DEFAULT_STATUS_CALLBACK;
+
+    my $dbh = DBI->connect("dbi:SQLite:dbname=$db_file", '', '', {RaiseError => 1});
+    my $select_sth = $dbh->prepare('SELECT FILENAME FROM mp3');
+    my $delete_sth = $dbh->prepare('DELETE FROM mp3 WHERE FILENAME = ?');
+    
+    # the number of records removed
+    my $count = 0;
+    
+    $select_sth->execute;
+    while (my ($filename) = $select_sth->fetchrow_array) {
+        unless (-e $filename) {
+            $delete_sth->execute($filename);
+            $status_callback->(D => $filename);
+            $count++;
+        }
+    }
+    
+    return $count;    
+}
+
 =head2 destroy_db
 
