File:  [Local Repository] / db / prgsrc / updateindex.pl
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Wed Oct 18 18:48:58 2000 UTC (23 years, 6 months ago) by boris
Branches: MAIN
CVS tags: HEAD
Initial revision

#!/usr/local/bin/perl -w

=head1 NAME

updateindex.pl - a script for creation of new database. 

=head1 SYNOPSIS

updateind.pl [B<-i> I<indexfile>]


=head1 DESCRIPTION

Upadets metainformation in the B<chgk> databse. Uses file
    L<./index> unless [B<-i>] option is used

An example of the index file follows:


=head1 BUGS

The database, user and password are hardcoded. 

=head1 SEE ALSO

createindex.pl(1)

=head1 AUTHOR

Boris Veytsman

=head1 $Id: updateindex.pl,v 1.1 2000/10/18 18:48:58 boris Exp $

=cut

    use strict;
use vars qw($opt_m);

use Getopt::Std;
use DBI;

MAIN: 
{
    getopts('m:') or die "Wrong options";
	my($source) = $opt_m || 'meta';
	my($depth, @depthId);
	my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "") 
		or die "Can't connect to DB chgk\n";

	open INFD, $source or die "Can't open input file: $!\n";
	while (<INFD>) {
	    my $MetaId;
		s/^\[(\d*)\]\t//;
		$MetaId = $1;
		s/^(\t*)//;
		chomp;
		$depth = length($1);
		my $title = $dbh->quote($_);
		my $ParentId = ($depth) ? $depthId[$depth - 1] : 0;
		my ($sth) = $dbh->prepare("SELECT Id FROM Tournaments WHERE
			MetaId=$MetaId");
		$sth->execute;
		if ($sth->fetchrow) {
			print "$title is already in the DB!\n";
			next;
		}
		$sth = $dbh->prepare("INSERT INTO Tournaments
			(Title, ParentId, MetaId, Type) 
			VALUES ($title, $ParentId, $MetaId, 'ç')");
		$sth->execute;
		my $Id = $sth->{'mysql_insertid'};
		$depthId[$depth] = $Id;
	}
	$dbh->disconnect;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>