Diff for /db/prgsrc/updateindex.pl between versions 1.1 and 1.2

version 1.1, 2000/10/18 18:48:58 version 1.2, 2000/10/18 21:50:48
Line 34  Boris Veytsman Line 34  Boris Veytsman
 =cut  =cut
   
     use strict;      use strict;
 use vars qw($opt_m);  use vars qw($opt_i $opt_h);
   
 use Getopt::Std;  use Getopt::Std;
 use DBI;  use DBI;
   
 MAIN:   MAIN: 
 {  {
     getopts('m:') or die "Wrong options";      my $USAGE="Usage: updateindex.pl -i indexfile\n";
         my($source) = $opt_m || 'meta';      getopts('hm:') or die $USAGE;
         my($depth, @depthId);      if ($opt_h) {
         my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "")           print $USAGE;
                 or die "Can't connect to DB chgk\n";          exit 0;
       }
       my($source) = $opt_i || 'index';
       my($depth, @depthId);
       my $filename;
       my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "") 
           or die "Can't connect to DB chgk\n";
   
         open INFD, $source or die "Can't open input file: $!\n";      open INFD, $source or die "Can't open input file: $!\n";
         while (<INFD>) {      while (<INFD>) {
             my $MetaId;          chomp;
                 s/^\[(\d*)\]\t//;          s/ //;
                 $MetaId = $1;          next if (/^\s*$/);
                 s/^(\t*)//;          if (s/^(\w*)//) { # File found
                 chomp;              $filename = $1;
                 $depth = length($1);              $depth = -1;
                 my $title = $dbh->quote($_);          } else {  # Group found
                 my $ParentId = ($depth) ? $depthId[$depth - 1] : 0;              undef $filename;
                 my ($sth) = $dbh->prepare("SELECT Id FROM Tournaments WHERE              $depth = -2;
                         MetaId=$MetaId");  
                 $sth->execute;  
                 if ($sth->fetchrow) {  
                         print "$title is already in the DB!\n";  
                         next;  
                 }  
                 $sth = $dbh->prepare("INSERT INTO Tournaments  
                         (Title, ParentId, MetaId, Type)   
                         VALUES ($title, $ParentId, $MetaId, 'ç')");  
                 $sth->execute;  
                 my $Id = $sth->{'mysql_insertid'};  
                 $depthId[$depth] = $Id;  
         }          }
         $dbh->disconnect;          s/^(\t*)//;
           $depth += length($1);
           if ($depth < 0) {
               die "Wrong line $_\n";
           }
           s/^\s*//;
           s/\s$//;
           my $title = $dbh->quote($_);
           my $ParentId = ($depth) ? $depthId[$depth - 1] : 0;
           my $sth;
           my $type;
           if (defined $filename) {
               $type=$dbh->quote('þ');
               $filename = $dbh->quote($filename);
               $sth = $dbh->prepare("SELECT Id FROM Tournaments 
                                     WHERE FileName=$filename");
               $sth->execute;
               if ($sth->fetchrow) {
                   print "$filename is already in the DB!\n";
                   next;
               }
               $sth = $dbh->prepare("INSERT INTO Tournaments
                           (Title, ParentId, FileName, Type) 
                           VALUES ($title, $ParentId, $filename, $type;)");
               $sth->execute;
           } else {
               $sth->execute;
               $sth = $dbh->prepare("SELECT Id FROM Tournaments 
                                     WHERE Title=$title");
               $type=$dbh->quote('ç');
               if ($sth->fetchrow) {
                   print "$title is already in the DB!\n";
                   next;
               }
               $sth = $dbh->prepare("INSERT INTO Tournaments
                           (Title, ParentId,  Type) 
                           VALUES ($title, $ParentId, $type;)");
               $sth->execute;
               my $Id = $sth->{'mysql_insertid'};
               $depthId[$depth] = $Id;
           }
   
       }
       $dbh->disconnect;
 }  }

Removed from v.1.1  
changed lines
  Added in v.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>