Diff for /db/prgsrc/updatedb.pl between versions 1.6 and 1.7

version 1.6, 2000/10/18 02:01:19 version 1.7, 2000/10/19 03:05:39
Line 95  sub getField { Line 95  sub getField {
 }  }
   
 sub SelectGroup {  sub SelectGroup {
     my ($dbh, $TourName, $sth, $ParentId, $i, @arr) = @_;      my ($dbh, $source, $TourName) = @_;
       my ($sth, $ParentId, $i, @arr);
           
     $sth = $dbh->prepare("SELECT Id, Title FROM      $sth = $dbh->prepare("SELECT Id, Title FROM
                 Tournaments WHERE Type = 'Г'");                  Tournaments WHERE Type = 'Г'");
     $sth->execute;      $sth->execute;
     print "Выберите группу для турнира:\n$TourName\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>;
     print "Вы выбрали турнир: $ParentId\n";      if (!$ParentId) {
     return $ParentId;          print "Пропускаем файл $source\n";
           print STDERR "Файл $source отвергнут оператором\n";
           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);
       }
                   
       
 }  }
   
 sub UpdateTournament {  sub UpdateTournament {
Line 122  sub UpdateQuestion { Line 137  sub UpdateQuestion {
         or die $dbh->errstr;          or die $dbh->errstr;
 }  }
   
   sub CheckFile {
       my ($dbh, $source,$title) = @_;
       my $sth = $dbh->prepare("SELECT Id,ParentId,QuestionsNum FROM Tournaments
                                WHERE FileName=$source AND Type='Ч'");
       $sth->execute or die $dbh->errstr;
       my @arr = $sth->fetchrow;
       if (! scalar @arr) {
           return SelectGroup($dbh,$source,$title);
       }
       my($Id,$ParentId,$QuestionsNum)=@arr;
       if($QuestionsNum) {
           print "Файл $source с данными $title уже существует. ",
           "Заменить?[y/N]\n";
           my $answer = <STDIN>;
           if ($answer !~ /^[yY]/) {
               return (0,0);
           } else {
               DeleteTournament($dbh,$Id,0);
           }
       } 
       return($Id,$ParentId);      
   }
   
   
   sub DeleteTournament {
       my ($dbh,$Id,$DeleteMyself) = @_;
       my (@Tours) = &GetTours($dbh, $Id);
       foreach my $Tour (@Tours) {
           DeleteTournament($dbh,$Tour,1);
       }
       my $sth = $dbh->prepare("DELETE FROM Questions
                                WHERE ParentId=$Id");
       $sth->execute or die $dbh->errstr;
       if($DeleteMyself) {
           $sth = $dbh->prepare("DELETE FROM Tournaments
                                WHERE Id=$Id");
       }
   }
 MAIN:   MAIN: 
 {  {
     my($key, $value, $addition);      my($key, $value, $addition);
Line 151  MAIN: Line 204  MAIN:
             last if (!$key);              last if (!$key);
                           
             if ($key =~ /Мета/) {              if ($key =~ /Мета/) {
                 $value =~ s/[^\d]*//g;                  next;   # This is obsolete
                 $sth = $dbh->prepare("SELECT Id FROM Tournaments WHERE  
                                         MetaId=$value");  
                 $sth->execute   
                     or die "Invalid Meta field: $value";  
                 $ParentId = ($sth->fetchrow)[0];  
                 next;  
             }              }
             if ($key =~ /Чемпионат/ || $key =~ /Пакет/) {              if ($key =~ /Чемпионат/ || $key =~ /Пакет/) {
                 $ParentId = &SelectGroup($dbh, $value)                  ($TournamentId, $ParentId) = CheckFile($dbh,$source,$value);
                     unless ($ParentId);                  if (!$TournamentId)  {
                 $sth = $dbh->prepare("INSERT INTO Tournaments                      last;
                                      (Title, Type, ParentId, FileName,                   }
                                       CreatedAt)                   $sth = $dbh->prepare("UPDATE Tournaments SET
                                       VALUES ($value, 'Ч', $ParentId,                                        Title=$value, Type='Ч', 
                                        $source, $CreatedAt)");                                       ParentId=$ParentId, 
                                        FileName=$source, 
                                        CreatedAt=$CreatedAt
                                        WHERE
                                        Id=$TournamentId");
                 $sth->execute;                  $sth->execute;
                 $TournamentId = $sth->{mysql_insertid};  
                 next;                  next;
             }              }
             if ($key =~ /Тур/) {              if ($key =~ /Тур/) {
Line 186  MAIN: Line 236  MAIN:
                 $TourId = $sth->{mysql_insertid};                  $TourId = $sth->{mysql_insertid};
                 next;                  next;
             }              }
             if ($key =~ /Вид/) {              if ($key =~ /Вид/ || $key =~ /Тип/) {
                 $qtype = $value;                  $qtype = $value;
                 $qtype =~ s/\'//g;                  $qtype =~ s/\'//g;
                 next;                  next;
Line 208  MAIN: Line 258  MAIN:
                 &UpdateQuestion($dbh, $QuestionId, "Answer", $value);                  &UpdateQuestion($dbh, $QuestionId, "Answer", $value);
                 next;                  next;
             }              }
   
               if ($key =~ /Рейтинг/) {
                   &UpdateQuestion($dbh, $QuestionId, "Rating", $value);
                   next;
               }
                           
   
             if ($key =~ /Автор/) {              if ($key =~ /Автор/) {
Line 228  MAIN: Line 283  MAIN:
             }              }
                           
   
             if ($key =~ /URL/ || key =~ /Ссылка/) {              if ($key =~ /URL/ || $key =~ /Ссылка/) {
                 &UpdateTournament($dbh, $TournamentId, "URL", $value);                  &UpdateTournament($dbh, $TournamentId, "URL", $value);
                 next;                  next;
             }              }

Removed from v.1.6  
changed lines
  Added in v.1.7


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