--- db/prgsrc/updatedb.pl 2003/02/07 23:20:15 1.34 +++ db/prgsrc/updatedb.pl 2004/01/07 14:31:31 1.37 @@ -28,7 +28,7 @@ The database, user and password are hard Dmitry Rubinstein -=head1 $Id: updatedb.pl,v 1.34 2003/02/07 23:20:15 roma7 Exp $ +=head1 $Id: updatedb.pl,v 1.37 2004/01/07 14:31:31 boris Exp $ =cut @@ -61,19 +61,22 @@ use DBI; use strict; my $isunsorted=0; sub UpdateParents { - my ($dbh, $ParentId, $all_qnum) = @_; + my ($dbh, $ParentId, $all_qnum,$CreatedAt) = @_; if ($ParentId) { - my ($sth1) = $dbh->prepare("SELECT QuestionsNum, ParentId + my ($sth1) = $dbh->prepare("SELECT QuestionsNum, ParentId, CreatedAt FROM Tournaments WHERE Id = $ParentId"); $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 - QuestionsNum=$q + $all_qnum + QuestionsNum=$q + $all_qnum, CreatedAt=$qc WHERE Id = $ParentId"); - &UpdateParents($dbh, $p, $all_qnum); + &UpdateParents($dbh, $p, $all_qnum,$c); } } + sub getField { my($desc, $dbh) = @_; my($key); @@ -90,6 +93,7 @@ sub getField { $value =~ s/-(.*)-/-$month-/; $value =~ s/-00*$/-01/; } + if ($key eq 'Автор') {$value=~s/\.$//;} $value = $dbh->quote($value); return ($key, $value); } @@ -285,13 +289,18 @@ MAIN: my($tournum, $qnum, $all_qnum) = (0, 0, 0); my (@d) = (localtime((stat($source))[9]))[5,4,3]; $d[1]++; + $d[1]=sprintf("%02d",$d[1]); + $d[2]=sprintf("%02d",$d[2]); $d[0]+=1900; - my ($CreatedAt) = $dbh->quote( join('-', @d)); + my $UnquotedCreated=join('-', @d); + my ($CreatedAt) = $dbh->quote($UnquotedCreated); open INFD, $source or die "Can't open input file: $!\n"; $source =~ s/^.*\/([^\/]*)$/$1/; + my $unquotedsource=$source; + $unquotedsource=~s/\.txt\s*$//; $source = $dbh->quote($source); print STDERR "Файл: $source, дата: $CreatedAt "; my %TourDefaults=('CreatedAt'=>$CreatedAt); @@ -320,11 +329,15 @@ MAIN: } if ($key =~ /Тур/) { if ($TourId) { - $dbh->do("UPDATE Tournaments SET QuestionsNum=$qnum + + $dbh->do("UPDATE Tournaments SET QuestionsNum=$qnum WHERE Id=$TourId"); } $qnum = 0; $TourNum++; + $TourDefaults{'FileName'}=$dbh->quote( + "$unquotedsource.$TourNum" + ); $TourId=CreateTour($dbh,$value,$TournamentId,$TourNum, \%TourDefaults); %QuestionDefaults=%QuestionGlobalDefaults; @@ -359,6 +372,14 @@ MAIN: next; } + + if ($key =~ /Зач[её]т/) { + &UpdateQuestion($dbh, $QuestionId, "PassCriteria", $value); + next; + } + + + if ($key =~ /Комментари/) { &UpdateQuestion($dbh, $QuestionId, "Comments", $value); next; @@ -407,7 +428,7 @@ MAIN: WHERE Id=$TourId"); $dbh->do("UPDATE Tournaments SET QuestionsNum=$all_qnum WHERE Id=$TournamentId"); - &UpdateParents($dbh, $ParentId, $all_qnum); + &UpdateParents($dbh, $ParentId, $all_qnum,$UnquotedCreated); print STDERR "Всего вопросов: $all_qnum \n"; } close UNSORTED;