Diff for /db/prgsrc/updatedb.pl between versions 1.35 and 1.43

version 1.35, 2003/02/24 13:59:27 version 1.43, 2008/11/14 11:23:03
Line 61  use DBI; Line 61  use DBI;
 use strict;  use strict;
 my $isunsorted=0;  my $isunsorted=0;
 sub UpdateParents {  sub UpdateParents {
     my ($dbh, $ParentId, $all_qnum) = @_;      my ($dbh, $ParentId, $all_qnum,$CreatedAt) = @_;
     if ($ParentId) {      if ($ParentId) {
         my ($sth1) = $dbh->prepare("SELECT QuestionsNum, ParentId           my ($sth1) = $dbh->prepare("SELECT QuestionsNum, ParentId, CreatedAt
 FROM Tournaments WHERE Id = $ParentId");  FROM Tournaments WHERE Id = $ParentId");
         $sth1->execute;          $sth1->execute;
         my ($q, $p) = ($sth1->fetchrow)[0, 1];          my ($q, $p,$c) = ($sth1->fetchrow)[0, 1, 2];
           $c=$CreatedAt if $CreatedAt && ($CreatedAt gt $c);
           my $qc=$dbh->quote($c);
         $dbh->do("UPDATE Tournaments SET           $dbh->do("UPDATE Tournaments SET 
                   QuestionsNum=$q + $all_qnum                     QuestionsNum=$q + $all_qnum, CreatedAt=$qc
                   WHERE Id = $ParentId");                    WHERE Id = $ParentId");
         &UpdateParents($dbh, $p, $all_qnum);          &UpdateParents($dbh, $p, $all_qnum,$c);
     }      }
 }  }
   
   
 sub getField {  sub getField {
     my($desc, $dbh) = @_;      my($desc, $dbh) = @_;
     my($key);      my($key);
Line 153  sub SelectGroup { Line 156  sub SelectGroup {
                 print UNSORTED "$tempsource".((12 -length($source))x' ')."\t$temptname\n";                  print UNSORTED "$tempsource".((12 -length($source))x' ')."\t$temptname\n";
                 $isunsorted=1;                  $isunsorted=1;
                 $sth = $dbh->prepare("INSERT INTO Tournaments                  $sth = $dbh->prepare("INSERT INTO Tournaments
                               (Title, Type, ParentId, FileName)                                 (Title, Type, ParentId, FileName,CreatedAt) 
                                VALUES ($TourName, 'Ч', $ParentId,                                  VALUES ($TourName, 'Ч', $ParentId, 
                                        $source)");                                         $source,NOW())");
                 $sth->execute;                  $sth->execute;
                 my $TournamentId = $sth->{mysql_insertid};                  my $TournamentId = $sth->{mysql_insertid};
                 return ($TournamentId,$ParentId);                  return ($TournamentId,$ParentId);
Line 172  sub UpdateTournament { Line 175  sub UpdateTournament {
   
 sub UpdateQuestion {  sub UpdateQuestion {
     my ($dbh, $QuestionId, $field, $value) = @_;      my ($dbh, $QuestionId, $field, $value) = @_;
       
       if (($field eq 'Type') && ($value eq "'Д'")) {
            $value = "'ЧД'";
       }
     $dbh->do("UPDATE Questions SET $field=$value       $dbh->do("UPDATE Questions SET $field=$value 
                 WHERE QuestionId=$QuestionId")                  WHERE QuestionId=$QuestionId")
         or die $dbh->errstr;          or die $dbh->errstr;
Line 239  sub GetTours { Line 246  sub GetTours {
 sub CreateTour {  sub CreateTour {
     my ($dbh,$title,$ParentId,$TourNum,$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, Number)                                (Title, Type, ParentId, Number,CreatedAt) 
                              VALUES ($title, 'Т', $ParentId, $TourNum)");                               VALUES ($title, 'Т', $ParentId, $TourNum,NOW())");
     $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 274  MAIN: Line 281  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";
   if ($dbh->get_info( 18 )=~/^(5|(4.1))/)  {$dbh->do("SET NAMES 'koi8r'");}
     my @sources;              my @sources;        
     open UNSORTED, ">$unsortedname";      open UNSORTED, ">$unsortedname";
     while ($source = shift) {      while ($source = shift) {
Line 286  MAIN: Line 294  MAIN:
         my($tournum, $qnum, $all_qnum) = (0, 0, 0);          my($tournum, $qnum, $all_qnum) = (0, 0, 0);
         my (@d) = (localtime((stat($source))[9]))[5,4,3];          my (@d) = (localtime((stat($source))[9]))[5,4,3];
         $d[1]++;          $d[1]++;
           $d[1]=sprintf("%02d",$d[1]);
           $d[2]=sprintf("%02d",$d[2]);
         $d[0]+=1900;          $d[0]+=1900;
         my ($CreatedAt) = $dbh->quote( join('-', @d));          my $UnquotedCreated=join('-', @d);
           my ($CreatedAt) = $dbh->quote($UnquotedCreated);
   
         open INFD, $source           open INFD, $source 
             or die "Can't open input file: $!\n";              or die "Can't open input file: $!\n";
                   
         $source =~ s/^.*\/([^\/]*)$/$1/;          $source =~ s/^.*\/([^\/]*)$/$1/;
           my $unquotedsource=$source;
           $unquotedsource=~s/\.txt\s*$//;
         $source = $dbh->quote($source);          $source = $dbh->quote($source);
         print STDERR "Файл: $source, дата: $CreatedAt ";          print STDERR "Файл: $source, дата: $CreatedAt ";
         my %TourDefaults=('CreatedAt'=>$CreatedAt);          my %TourDefaults=('CreatedAt'=>$CreatedAt);
Line 321  MAIN: Line 334  MAIN:
             }              }
             if ($key =~ /Тур/) {              if ($key =~ /Тур/) {
                 if ($TourId) {                  if ($TourId) {
                     $dbh->do("UPDATE Tournaments SET QuestionsNum=$qnum  
                           $dbh->do("UPDATE Tournaments SET QuestionsNum=$qnum
                               WHERE Id=$TourId");                                WHERE Id=$TourId");
                 }                  }
                 $qnum = 0;                  $qnum = 0;
                 $TourNum++;                  $TourNum++;
                   $TourDefaults{'FileName'}=$dbh->quote(
                                                   "$unquotedsource.$TourNum"
                                                   );
                 $TourId=CreateTour($dbh,$value,$TournamentId,$TourNum,                  $TourId=CreateTour($dbh,$value,$TournamentId,$TourNum,
                                    \%TourDefaults);                                     \%TourDefaults);
                 %QuestionDefaults=%QuestionGlobalDefaults;                  %QuestionDefaults=%QuestionGlobalDefaults;
Line 360  MAIN: Line 377  MAIN:
                 next;                  next;
             }              }
   
   
               if ($key =~ /Зач[её]т/) {
                   &UpdateQuestion($dbh, $QuestionId, "PassCriteria", $value);
                   next;
               }
   
   
   
             if ($key =~ /Комментари/) {              if ($key =~ /Комментари/) {
                 &UpdateQuestion($dbh, $QuestionId, "Comments", $value);                  &UpdateQuestion($dbh, $QuestionId, "Comments", $value);
                 next;                  next;
             }              }
   
   
                           
             my @Fields = grep { $key =~ /$_/ } keys %QuestionFields;              my @Fields = grep { $key =~ /$_/ } keys %QuestionFields;
   
Line 408  MAIN: Line 435  MAIN:
                         WHERE Id=$TourId");                          WHERE Id=$TourId");
         $dbh->do("UPDATE Tournaments SET QuestionsNum=$all_qnum          $dbh->do("UPDATE Tournaments SET QuestionsNum=$all_qnum
                         WHERE Id=$TournamentId");                          WHERE Id=$TournamentId");
         &UpdateParents($dbh, $ParentId, $all_qnum);                       &UpdateParents($dbh, $ParentId, $all_qnum,$UnquotedCreated);            
         print STDERR "Всего вопросов: $all_qnum \n";          print STDERR "Всего вопросов: $all_qnum \n";
     }      }
     close UNSORTED;      close UNSORTED;

Removed from v.1.35  
changed lines
  Added in v.1.43


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