Diff for /db/prgsrc/updatedb.pl between versions 1.24 and 1.25

version 1.24, 2002/01/15 03:34:31 version 1.25, 2002/11/09 01:47:23
Line 6  updatedb.pl - a script for creation of n Line 6  updatedb.pl - a script for creation of n
   
 =head1 SYNOPSIS  =head1 SYNOPSIS
   
 updatedb.pl I<file1> I<file2>....  updatedb.pl B<[-i]> I<file1> I<file2>....
   
   
 =head1 DESCRIPTION  =head1 DESCRIPTION
   
 Updates information in the B<chgk> databse. Uses file  Updates information in the B<chgk> databse. Uses file
   
   =head1 OPTIONS
   
   =item B<-i> 
   
   Ask about ParentId. 
   
   
 =head1 BUGS  =head1 BUGS
   
Line 26  Dmitry Rubinstein Line 32  Dmitry Rubinstein
   
 =cut  =cut
   
   use vars qw($opt_i);
   
   use Getopt::Std;
   getopts('i');
   
   my $Interactive=$opt_i || 0;
   
   
 my (%RevMonths) =   my (%RevMonths) = 
     ('Jan', '1', 'Feb', '2', 'Mar', '3', 'Apr', '4', 'May', '5', 'Jun', '6',      ('Jan', '1', 'Feb', '2', 'Mar', '3', 'Apr', '4', 'May', '5', 'Jun', '6',
      'Jul', '7', 'Aug', '8', 'Sep', '9', 'Oct', '10', 'Nov', '11',       'Jul', '7', 'Aug', '8', 'Sep', '9', 'Oct', '10', 'Nov', '11',
Line 101  sub getField { Line 115  sub getField {
 sub SelectGroup {  sub SelectGroup {
     my ($dbh, $source, $TourName) = @_;      my ($dbh, $source, $TourName) = @_;
     my ($sth, $ParentId, $i, @arr);      my ($sth, $ParentId, $i, @arr);
       
     $sth = $dbh->prepare("SELECT Id, Title FROM      if ($Interactive) {    
           $sth = $dbh->prepare("SELECT Id, Title FROM
                 Tournaments WHERE Type = 'Г'");                  Tournaments WHERE Type = 'Г'");
     $sth->execute;          $sth->execute;
     print "Выберите группу для турнира:\n$TourName, файл $source\n\n";          print "Выберите группу для турнира:\n$TourName, файл $source\n\n";
     while (@arr=$sth->fetchrow) {          while (@arr=$sth->fetchrow) {
         print "[$arr[0]] $arr[1]\n";                  print "[$arr[0]] $arr[1]\n";
     }          }
     $ParentId = <STDIN>;          $ParentId = <STDIN>;
     chomp $ParentId;          chomp $ParentId;
     if (!$ParentId) {          if (!$ParentId) {
         print "Пропускаем файл $source\n";                  print "Пропускаем файл $source\n";
         print STDERR "Файл $source отвергнут оператором\n";                  print STDERR "Файл $source отвергнут оператором\n";
         return (0,0);                  return (0,0);
           } else {
                   print "Вы выбрали турнир: $ParentId\n";
                   $sth = $dbh->prepare("INSERT INTO Tournaments
                                 (Title, Type, ParentId, FileName) 
                                  VALUES ($TourName, 'Ч', $ParentId, 
                                          $source)");
                   $sth->execute;
                   my $TournamentId = $sth->{mysql_insertid};
                   return ($TournamentId,$ParentId);
           }
     } else {      } else {
         print "Вы выбрали турнир: $ParentId\n";  # Теперь, если файла нет в дереве турниров, никаких вопросов не 
         $sth = $dbh->prepare("INSERT INTO Tournaments  # задаётся, а вместо этого он добавляется в группу 9999
           $ParentId = 9999;
   print STDERR "INSERT INTO Tournaments
                                 (Title, Type, ParentId, FileName) 
                                  VALUES ($TourName, 'Ч', $ParentId, 
                                          $source)";
                   $sth = $dbh->prepare("INSERT INTO Tournaments
                               (Title, Type, ParentId, FileName)                                 (Title, Type, ParentId, FileName) 
                                VALUES ($TourName, 'Ч', $ParentId,                                  VALUES ($TourName, 'Ч', $ParentId, 
                                        $source)");                                         $source)");
         $sth->execute;                  $sth->execute;
         my $TournamentId = $sth->{mysql_insertid};                  my $TournamentId = $sth->{mysql_insertid};
         return ($TournamentId,$ParentId);                  return ($TournamentId,$ParentId);
     }          }
                                   
           
 }  }
Line 239  MAIN: Line 270  MAIN:
           
     my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "")      my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "")
         or die "Can't connect to DB chgk\n";          or die "Can't connect to DB chgk\n";
           my @sources;        
     while ($source = shift) {      while ($source = shift) {
          push @sources,glob($source);
       }
       foreach $source(@sources) {
         my $TourNum=0;          my $TourNum=0;
         my($PlayedAt) = '';          my($PlayedAt) = '';
         my($QuestionId, $TourId, $TournamentId, $ParentId) = (0, 0, 0, 0);          my($QuestionId, $TourId, $TournamentId, $ParentId) = (0, 0, 0, 0);

Removed from v.1.24  
changed lines
  Added in v.1.25


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