--- db/prgsrc/updatedb.pl 2000/10/22 06:03:35 1.15 +++ db/prgsrc/updatedb.pl 2002/01/12 00:55:33 1.22 @@ -22,7 +22,7 @@ The database, user and password are hard Dmitry Rubinstein -=head1 $Id: updatedb.pl,v 1.15 2000/10/22 06:03:35 boris Exp $ +=head1 $Id: updatedb.pl,v 1.22 2002/01/12 00:55:33 roma7 Exp $ =cut @@ -70,16 +70,18 @@ sub getField { chomp $key; if ($key eq 'Дата') { $value =~ s/^(.*)-(.*)-(.*)$/$3-$2-$1/; - my($month) = $RevMonths{$2} || '000'; - $value =~ s/$2/$month/; + my($month) = $RevMonths{$2} || '01'; + $value =~ s/-(.*)-/-$month-/; + $value =~ s/-00*$/-01/; } $value = $dbh->quote($value); return ($key, $value); } next if (/^\s*$/); - if (/^(.*)[:\.]\s*/ && !$key) { + if (!$key && /^(.*?)[:\.]\s*(.*)$/s) { $key = $1; + $value=$2; next; } if ($key) { @@ -133,6 +135,7 @@ sub UpdateTournament { sub UpdateQuestion { my ($dbh, $QuestionId, $field, $value) = @_; + $value=~s/\s*$//; $dbh->do("UPDATE Questions SET $field=$value WHERE QuestionId=$QuestionId") or die $dbh->errstr; @@ -198,10 +201,10 @@ sub GetTours { } sub CreateTour { - my ($dbh,$title,$ParentId,$rh_defaults)=@_; + my ($dbh,$title,$ParentId,$TourNum,$rh_defaults)=@_; my $sth = $dbh->prepare("INSERT INTO Tournaments - (Title, Type, ParentId) - VALUES ($title, 'Т', $ParentId)"); + (Title, Type, ParentId, Number) + VALUES ($title, 'Т', $ParentId, $TourNum)"); $sth->execute; my $TourId = $sth->{mysql_insertid}; while (my ($key,$value)=each %$rh_defaults) { @@ -227,7 +230,8 @@ MAIN: # my %QuestionFields = ('Тип'=> 'Type', 'Вид'=> 'Type', 'Автор' => 'Authors', 'Рейтинг'=>'Rating', - 'Источник' => 'Sources'); + 'Источник' => 'Sources', + 'Тема' => 'Topic'); my($source); @@ -236,6 +240,7 @@ MAIN: or die "Can't connect to DB chgk\n"; while ($source = shift) { + my $TourNum=0; my($PlayedAt) = ''; my($QuestionId, $TourId, $TournamentId, $ParentId) = (0, 0, 0, 0); my($tournum, $qnum, $all_qnum) = (0, 0, 0); @@ -280,7 +285,9 @@ MAIN: WHERE Id=$TourId"); } $qnum = 0; - $TourId=CreateTour($dbh,$value,$TournamentId,\%TourDefaults); + $TourNum++; + $TourId=CreateTour($dbh,$value,$TournamentId,$TourNum, + \%TourDefaults); %QuestionDefaults=%QuestionGlobalDefaults; $QuestionId=0; next; @@ -288,7 +295,8 @@ MAIN: if ($key =~ /Вопрос/) { if (!$TourId) { $qnum = 0; - $TourId=CreateTour($dbh,'1',$TournamentId, + $TourNum++; + $TourId=CreateTour($dbh,'1',$TournamentId,$TourNum, \%TourDefaults); %QuestionDefaults=%QuestionGlobalDefaults; }