version 1.2, 2000/10/18 21:50:48
|
version 1.5, 2000/10/19 03:05:18
|
Line 16 Upadets metainformation in the B<chgk> d
|
Line 16 Upadets metainformation in the B<chgk> d
|
|
|
An example of the index file follows: |
An example of the index file follows: |
|
|
|
Авторские вопросы |
|
Виктор Байрак |
|
bayrak.txt Вопросы В.Байрака |
|
Борис Бурда |
|
burda.txt Вопросы Бориса Бурды |
|
burda1.txt Тренировки Бориса Бурды 1 |
|
burda10.txt Тренировки Бориса Бурды 10 |
|
burda11.txt Тренировки Бориса Бурды 11 |
|
burda12.txt Тренировки Бориса Бурды 12 |
|
|
|
|
=head1 BUGS |
=head1 BUGS |
|
|
Line 42 use DBI;
|
Line 52 use DBI;
|
MAIN: |
MAIN: |
{ |
{ |
my $USAGE="Usage: updateindex.pl -i indexfile\n"; |
my $USAGE="Usage: updateindex.pl -i indexfile\n"; |
getopts('hm:') or die $USAGE; |
getopts('hi:') or die $USAGE; |
if ($opt_h) { |
if ($opt_h) { |
print $USAGE; |
print $USAGE; |
exit 0; |
exit 0; |
Line 58 MAIN:
|
Line 68 MAIN:
|
chomp; |
chomp; |
s/
//; |
s/
//; |
next if (/^\s*$/); |
next if (/^\s*$/); |
if (s/^(\w*)//) { # File found |
if (s/^(\S+) *//) { # File found |
$filename = $1; |
$filename = $1; |
$depth = -1; |
$depth = -1; |
} else { # Group found |
} else { # Group found |
undef $filename; |
$filename = ''; |
$depth = -2; |
$depth = -2; |
} |
} |
s/^(\t*)//; |
s/^(\t*)//; |
Line 72 MAIN:
|
Line 82 MAIN:
|
} |
} |
s/^\s*//; |
s/^\s*//; |
s/\s$//; |
s/\s$//; |
my $title = $dbh->quote($_); |
my $title = $_; |
my $ParentId = ($depth) ? $depthId[$depth - 1] : 0; |
my $ParentId = ($depth) ? $depthId[$depth - 1] : 0; |
my $sth; |
my $Id = CheckId($dbh,$title,$ParentId,$filename); |
my $type; |
if (!$Id || $filename) { |
if (defined $filename) { |
next; |
$type=$dbh->quote('Ч'); |
|
$filename = $dbh->quote($filename); |
|
$sth = $dbh->prepare("SELECT Id FROM Tournaments |
|
WHERE FileName=$filename"); |
|
$sth->execute; |
|
if ($sth->fetchrow) { |
|
print "$filename is already in the DB!\n"; |
|
next; |
|
} |
|
$sth = $dbh->prepare("INSERT INTO Tournaments |
|
(Title, ParentId, FileName, Type) |
|
VALUES ($title, $ParentId, $filename, $type;)"); |
|
$sth->execute; |
|
} else { |
|
$sth->execute; |
|
$sth = $dbh->prepare("SELECT Id FROM Tournaments |
|
WHERE Title=$title"); |
|
$type=$dbh->quote('Г'); |
|
if ($sth->fetchrow) { |
|
print "$title is already in the DB!\n"; |
|
next; |
|
} |
|
$sth = $dbh->prepare("INSERT INTO Tournaments |
|
(Title, ParentId, Type) |
|
VALUES ($title, $ParentId, $type;)"); |
|
$sth->execute; |
|
my $Id = $sth->{'mysql_insertid'}; |
|
$depthId[$depth] = $Id; |
|
} |
} |
|
$depthId[$depth] = $Id; |
|
|
} |
} |
$dbh->disconnect; |
$dbh->disconnect; |
} |
} |
|
|
|
|
|
sub CheckId { |
|
my ($dbh,$title,$ParentId,$filename) = @_; |
|
my $type; |
|
my $key; |
|
my $value; |
|
my $Id = 0; |
|
if ($filename) { |
|
$type=$dbh->quote('Ч'); |
|
$key = "FileName"; |
|
$value = $dbh->quote($filename); |
|
} else { |
|
$type=$dbh->quote('Г'); |
|
$key = "Title"; |
|
$value = $dbh->quote($title); |
|
} |
|
$title=$dbh->quote($title); |
|
my $sth = $dbh->prepare("SELECT Id FROM Tournaments |
|
WHERE $key=$value"); |
|
$sth->execute or die $dbh->errstr; |
|
my @arr = $sth->fetchrow; |
|
if (scalar @arr) { |
|
print "$value is already in the DB!\n"; |
|
print "Заменить новым значением? [y/N]\n"; |
|
my $answer = <STDIN>; |
|
if ($answer !~ /^[yY]/) { |
|
return 0; |
|
} else { |
|
$Id = $arr[0]; |
|
} |
|
} |
|
if ($Id) { |
|
$sth = $dbh->prepare("UPDATE Tournaments |
|
SET Title=$title, ParentId=$ParentId, |
|
Type=$type |
|
WHERE Id=$Id"); |
|
|
|
} else { |
|
$sth = $dbh->prepare("INSERT INTO Tournaments |
|
(Title, ParentId, Type) |
|
VALUES |
|
($title, $ParentId,$type)"); |
|
} |
|
$sth->execute or die $dbh->errstr; |
|
if (!$Id) { |
|
$Id = $sth->{'mysql_insertid'}; |
|
} |
|
if ($filename) { |
|
$filename=$dbh->quote($filename); |
|
$sth = $dbh->prepare("UPDATE Tournaments |
|
SET FileName=$filename |
|
WHERE Id=$Id"); |
|
$sth->execute or die $dbh->errstr; |
|
} |
|
return $Id; |
|
} |