--- db/prgsrc/updateindex.pl 2000/10/22 01:25:25 1.6 +++ db/prgsrc/updateindex.pl 2003/04/14 20:06:59 1.9 @@ -6,7 +6,7 @@ updateindex.pl - a script for creation o =head1 SYNOPSIS -updateind.pl [B<-i> I] [B<-y>|B<-n>] +updateind.pl [B<-i> I] [B<-y>|B<-n>] [B<-r>] =head1 DESCRIPTION @@ -42,6 +42,10 @@ Answer 'yes' to all questions Answer 'no' to all questions +=item B<-r> + +Remove all entries with zero QuestionNum + =head1 BUGS The database, user and password are hardcoded. @@ -54,20 +58,21 @@ createindex.pl(1) Boris Veytsman -=head1 $Id: updateindex.pl,v 1.6 2000/10/22 01:25:25 boris Exp $ +=head1 $Id: updateindex.pl,v 1.9 2003/04/14 20:06:59 roma7 Exp $ =cut use strict; -use vars qw($opt_i $opt_h $opt_y $opt_n); +use vars qw($opt_i $opt_h $opt_y $opt_n $opt_r); use Getopt::Std; use DBI; MAIN: { - my $USAGE="Usage: updateindex.pl [-i indexfile] [-y|-n]\n"; - getopts('hi:yn') or die $USAGE; + my $USAGE="Usage: updateindex.pl [-i indexfile] [-y|-n][-r]\n"; + my $REMOVE=0; + getopts('hi:ynr') or die $USAGE; if ($opt_h) { print $USAGE; exit 0; @@ -79,7 +84,11 @@ MAIN: if ($opt_n ) { $decision = 'no'; } + if ($opt_r) { + $REMOVE=1; + } my($source) = $opt_i; + my $champ; my($depth, @depthId); my $filename; my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "") @@ -90,16 +99,22 @@ MAIN: } else { *INFO=*STDIN; } + while () { chomp; s/ //; next if (/^\s*$/); - if (s/^(\S+) *//) { # File found + if (s/^(\S+\.txt) *//) { # File found $filename = $1; $depth = -1; + $champ=1; } else { # Group found - $filename = ''; + if (s/^(\S+)//) + { $filename = $1;} + else + {$filename = ''} $depth = -2; + $champ=0; } s/^(\t*)//; $depth += length($1); @@ -111,7 +126,7 @@ MAIN: my $title = $_; my $ParentId = ($depth) ? $depthId[$depth - 1] : 0; my $Id = CheckId($dbh,$title,$ParentId,$decision,$filename); - if (!$Id || $filename) { + if (!$Id || $champ) { next; } $depthId[$depth] = $Id; @@ -119,6 +134,15 @@ MAIN: } print STDERR "Всего вопросов: ", UpdateGroup($dbh,0),"\n"; + if ($REMOVE) { + print STDERR "Removing empty tours."; + $dbh->do("DELETE FROM Tournaments WHERE QuestionsNum=0"); + } + $dbh->do("INSERT INTO Tournaments + (Id, Title, ParentId, Type) + VALUES + (9999, 'Несортированные турниры', 0,'Г')"); + $dbh->disconnect; } @@ -128,16 +152,19 @@ sub CheckId { my $type; my $key; my $value; - my $Id = 0; - if ($filename) { + my $Id = 0; + if ($filename && $filename=~/\.txt/) { $type=$dbh->quote('Ч'); - $key = "FileName"; - $value = $dbh->quote($filename); + } else {$type=$dbh->quote('Г');} + if ($filename) + { + $key = "FileName"; + $value = $dbh->quote($filename); } else { - $type=$dbh->quote('Г'); - $key = "Title"; - $value = $dbh->quote($title); + $key = "Title"; + $value = $dbh->quote($title); } + $title=$dbh->quote($title); my $sth = $dbh->prepare("SELECT Id FROM Tournaments WHERE $key=$value");