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

version 1.15, 2000/10/22 06:03:35 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 67  sub getField { Line 81  sub getField {
         s/[ ]//g;          s/[ ]//g;
         if ($key && /^\s*$/) {          if ($key && /^\s*$/) {
             chomp $value;              chomp $value;
               $value =~ s/\s+$//;
             chomp $key;              chomp $key;
             if ($key eq 'Дата') {              if ($key eq 'Дата') {
                 $value =~ s/^(.*)-(.*)-(.*)$/$3-$2-$1/;                  $value =~ s/^(.*)-(.*)-(.*)$/$3-$2-$1/;
                 my($month) = $RevMonths{$2} || '000';                  my($month) = $RevMonths{$2} || '01';
                 $value =~ s/$2/$month/;                  $value =~ s/-(.*)-/-$month-/;
                   $value =~ s/-00*$/-01/;
             }              }
             $value = $dbh->quote($value);              $value = $dbh->quote($value);
             return ($key, $value);              return ($key, $value);
         }          }
         next if (/^\s*$/);          next if (/^\s*$/);
                   
         if (/^(.*)[:\.]\s*/ && !$key) {          if (!$key && /^(.*?)[:\.]\s*(.*)$/s) {
             $key = $1;              $key = $1;
               $value=$2;
             next;              next;
         }          }
         if ($key) {          if ($key) {
Line 88  sub getField { Line 105  sub getField {
         }          }
     }      }
     if ($key && $value) {      if ($key && $value) {
           $value=~s/\s+$//;
         $value = $dbh->quote($value);          $value = $dbh->quote($value);
         return ($key, $value);          return ($key, $value);
     }      }
Line 97  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 198  sub GetTours { Line 233  sub GetTours {
 }  }
   
 sub CreateTour {  sub CreateTour {
     my ($dbh,$title,$ParentId,$rh_defaults)=@_;      my ($dbh,$title,$ParentId,$TourNum,$rh_defaults)=@_;
     my $sth = $dbh->prepare("INSERT INTO Tournaments      my $sth = $dbh->prepare("INSERT INTO Tournaments
                              (Title, Type, ParentId)                                (Title, Type, ParentId, Number) 
                              VALUES ($title, 'Т', $ParentId)");                               VALUES ($title, 'Т', $ParentId, $TourNum)");
     $sth->execute;      $sth->execute;
     my $TourId = $sth->{mysql_insertid};      my $TourId = $sth->{mysql_insertid};
     while (my ($key,$value)=each %$rh_defaults) {      while (my ($key,$value)=each %$rh_defaults) {
Line 227  MAIN: Line 262  MAIN:
     #      #
     my %QuestionFields = ('Тип'=> 'Type', 'Вид'=> 'Type',       my %QuestionFields = ('Тип'=> 'Type', 'Вид'=> 'Type', 
                           'Автор' => 'Authors', 'Рейтинг'=>'Rating',                             'Автор' => 'Authors', 'Рейтинг'=>'Rating', 
                           'Источник' => 'Sources');                            'Источник' => 'Sources',
                             'Тема' => 'Topic');
                                                       
                                               
     my($source);      my($source);
           
     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($PlayedAt) = '';          my($PlayedAt) = '';
         my($QuestionId, $TourId, $TournamentId, $ParentId) = (0, 0, 0, 0);          my($QuestionId, $TourId, $TournamentId, $ParentId) = (0, 0, 0, 0);
         my($tournum, $qnum, $all_qnum) = (0, 0, 0);          my($tournum, $qnum, $all_qnum) = (0, 0, 0);
Line 280  MAIN: Line 320  MAIN:
                               WHERE Id=$TourId");                                WHERE Id=$TourId");
                 }                  }
                 $qnum = 0;                  $qnum = 0;
                 $TourId=CreateTour($dbh,$value,$TournamentId,\%TourDefaults);                  $TourNum++;
                   $TourId=CreateTour($dbh,$value,$TournamentId,$TourNum,
                                      \%TourDefaults);
                 %QuestionDefaults=%QuestionGlobalDefaults;                  %QuestionDefaults=%QuestionGlobalDefaults;
                 $QuestionId=0;                  $QuestionId=0;
                 next;                     next;   
Line 288  MAIN: Line 330  MAIN:
             if ($key =~ /Вопрос/) {              if ($key =~ /Вопрос/) {
                 if (!$TourId) {                  if (!$TourId) {
                     $qnum = 0;                      $qnum = 0;
                     $TourId=CreateTour($dbh,'1',$TournamentId,                      $TourNum++;
                       $TourId=CreateTour($dbh,'1',$TournamentId,$TourNum,
                                        \%TourDefaults);                                         \%TourDefaults);
                     %QuestionDefaults=%QuestionGlobalDefaults;                      %QuestionDefaults=%QuestionGlobalDefaults;
                 }                  }

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


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