version 1.1, 2000/10/18 18:48:58
|
version 1.3, 2000/10/19 01:06: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 34 Boris Veytsman
|
Line 44 Boris Veytsman
|
=cut |
=cut |
|
|
use strict; |
use strict; |
use vars qw($opt_m); |
use vars qw($opt_i $opt_h); |
|
|
use Getopt::Std; |
use Getopt::Std; |
use DBI; |
use DBI; |
|
|
MAIN: |
MAIN: |
{ |
{ |
getopts('m:') or die "Wrong options"; |
my $USAGE="Usage: updateindex.pl -i indexfile\n"; |
my($source) = $opt_m || 'meta'; |
getopts('hi:') or die $USAGE; |
my($depth, @depthId); |
if ($opt_h) { |
my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "") |
print $USAGE; |
or die "Can't connect to DB chgk\n"; |
exit 0; |
|
} |
open INFD, $source or die "Can't open input file: $!\n"; |
my($source) = $opt_i || 'index'; |
while (<INFD>) { |
my($depth, @depthId); |
my $MetaId; |
my $filename; |
s/^\[(\d*)\]\t//; |
my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "") |
$MetaId = $1; |
or die "Can't connect to DB chgk\n"; |
s/^(\t*)//; |
|
chomp; |
open INFD, $source or die "Can't open input file: $!\n"; |
$depth = length($1); |
while (<INFD>) { |
my $title = $dbh->quote($_); |
chomp; |
my $ParentId = ($depth) ? $depthId[$depth - 1] : 0; |
s/
//; |
my ($sth) = $dbh->prepare("SELECT Id FROM Tournaments WHERE |
next if (/^\s*$/); |
MetaId=$MetaId"); |
if (s/^(\S+) *//) { # File found |
$sth->execute; |
$filename = $1; |
if ($sth->fetchrow) { |
$depth = -1; |
print "$title is already in the DB!\n"; |
} else { # Group found |
next; |
$filename = ''; |
} |
$depth = -2; |
$sth = $dbh->prepare("INSERT INTO Tournaments |
} |
(Title, ParentId, MetaId, Type) |
s/^(\t*)//; |
VALUES ($title, $ParentId, $MetaId, 'Г')"); |
$depth += length($1); |
$sth->execute; |
if ($depth < 0) { |
my $Id = $sth->{'mysql_insertid'}; |
die "Wrong line $_\n"; |
$depthId[$depth] = $Id; |
|
} |
} |
$dbh->disconnect; |
s/^\s*//; |
|
s/\s$//; |
|
my $title = $dbh->quote($_); |
|
my $ParentId = ($depth) ? $depthId[$depth - 1] : 0; |
|
my $sth; |
|
my $type; |
|
if ($filename) { |
|
$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 { |
|
$type=$dbh->quote('Г'); |
|
$sth = $dbh->prepare("SELECT Id FROM Tournaments |
|
WHERE Title=$title"); |
|
|
|
$sth->execute; |
|
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; |
|
} |
|
|
|
} |
|
$dbh->disconnect; |
} |
} |