create-v4, report, update: Keep track of which box each disc is in.
[dvddb] / report
diff --git a/report b/report
index 7fb00b7..29d1d7e 100755 (executable)
--- a/report
+++ b/report
@@ -26,9 +26,10 @@ find(sub {
 
 my %set_path;
 my %set_id;
+my %box;
 my $st_set = $DB->prepare("SELECT id, name, n_disc FROM dvd_set");
 my $st_disc = $DB->prepare
-  ("SELECT disc, path FROM dvd_disc WHERE set_id = ? ORDER BY disc");
+  ("SELECT disc, path, box FROM dvd_disc WHERE set_id = ? ORDER BY disc");
 $st_set->execute;
 
 while (my @r = $st_set->fetchrow_array) {
@@ -37,8 +38,9 @@ while (my @r = $st_set->fetchrow_array) {
 
   $st_disc->execute($id);
   while (my @r = $st_disc->fetchrow_array) {
-    my ($disc, $path) = @r;
+    my ($disc, $path, $box) = @r;
     $disc == @path or die "bad disc sequence for `$name'";
+    $box{$path} = $box if defined $box;
     push @path, $path;
   }
   @path == $ndisc or die "wrong number of discs for `$name'";
@@ -55,10 +57,18 @@ for my $name (keys %set_path) {
 }
 
 my @iso = sort keys %iso;
+my $lastbox = "#nil";
+sub set_box ($) {
+  my ($box) = @_;
+  $box //= "#nil";
+  if ($box ne $lastbox) { print "!box $box\n"; $lastbox = $box; }
+}
+
 for my $name (sort { $set_path{$a}[0] cmp $set_path{$b}[0] }
                keys %set_path) {
   my $paths = $set_path{$name};
   my @unk;
+  set_box $box{$paths->[0]};
   while (@iso && $iso[0] lt $paths->[0]) { push @unk, shift @iso; }
   if (@unk) {
     print "[#UNK: *]\n";
@@ -72,6 +82,7 @@ for my $name (sort { $set_path{$a}[0] cmp $set_path{$b}[0] }
       printf "\t!! (disc %d)\n", $i;
     } else {
       my $fn = "$ROOT/$path";
+      set_box $box{$path};
       if (-f $fn && ! -l $fn) { print "\t" . $path . "\n"; }
       else { print "\t!! ". $path . "\n"; }
     }