--- db/prgsrc/updatedb.pl 2002/01/15 03:34:31 1.24 +++ db/prgsrc/updatedb.pl 2002/11/09 01:47:23 1.25 @@ -6,13 +6,19 @@ updatedb.pl - a script for creation of n =head1 SYNOPSIS -updatedb.pl I I.... +updatedb.pl B<[-i]> I I.... =head1 DESCRIPTION Updates information in the B databse. Uses file +=head1 OPTIONS + +=item B<-i> + +Ask about ParentId. + =head1 BUGS @@ -22,10 +28,18 @@ The database, user and password are hard Dmitry Rubinstein -=head1 $Id: updatedb.pl,v 1.24 2002/01/15 03:34:31 roma7 Exp $ +=head1 $Id: updatedb.pl,v 1.25 2002/11/09 01:47:23 roma7 Exp $ =cut +use vars qw($opt_i); + +use Getopt::Std; +getopts('i'); + +my $Interactive=$opt_i || 0; + + my (%RevMonths) = ('Jan', '1', 'Feb', '2', 'Mar', '3', 'Apr', '4', 'May', '5', 'Jun', '6', 'Jul', '7', 'Aug', '8', 'Sep', '9', 'Oct', '10', 'Nov', '11', @@ -101,30 +115,47 @@ sub getField { sub SelectGroup { my ($dbh, $source, $TourName) = @_; my ($sth, $ParentId, $i, @arr); - - $sth = $dbh->prepare("SELECT Id, Title FROM + + if ($Interactive) { + $sth = $dbh->prepare("SELECT Id, Title FROM Tournaments WHERE Type = 'Г'"); - $sth->execute; - print "Выберите группу для турнира:\n$TourName, файл $source\n\n"; - while (@arr=$sth->fetchrow) { - print "[$arr[0]] $arr[1]\n"; - } - $ParentId = ; - chomp $ParentId; - if (!$ParentId) { - print "Пропускаем файл $source\n"; - print STDERR "Файл $source отвергнут оператором\n"; - return (0,0); + $sth->execute; + print "Выберите группу для турнира:\n$TourName, файл $source\n\n"; + while (@arr=$sth->fetchrow) { + print "[$arr[0]] $arr[1]\n"; + } + $ParentId = ; + chomp $ParentId; + if (!$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); + } } 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) VALUES ($TourName, 'Ч', $ParentId, $source)"); - $sth->execute; - my $TournamentId = $sth->{mysql_insertid}; - return ($TournamentId,$ParentId); - } + $sth->execute; + my $TournamentId = $sth->{mysql_insertid}; + return ($TournamentId,$ParentId); + } } @@ -239,8 +270,11 @@ MAIN: my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "") or die "Can't connect to DB chgk\n"; - + my @sources; while ($source = shift) { + push @sources,glob($source); + } + foreach $source(@sources) { my $TourNum=0; my($PlayedAt) = ''; my($QuestionId, $TourId, $TournamentId, $ParentId) = (0, 0, 0, 0);