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, 7 months ago) by boris
Branches: MAIN
CVS tags: HEAD
Initial revision

    1: #!/usr/local/bin/perl -w
    2: 
    3: =head1 NAME
    4: 
    5: updateindex.pl - a script for creation of new database. 
    6: 
    7: =head1 SYNOPSIS
    8: 
    9: updateind.pl [B<-i> I<indexfile>]
   10: 
   11: 
   12: =head1 DESCRIPTION
   13: 
   14: Upadets metainformation in the B<chgk> databse. Uses file
   15:     L<./index> unless [B<-i>] option is used
   16: 
   17: An example of the index file follows:
   18: 
   19: 
   20: =head1 BUGS
   21: 
   22: The database, user and password are hardcoded. 
   23: 
   24: =head1 SEE ALSO
   25: 
   26: createindex.pl(1)
   27: 
   28: =head1 AUTHOR
   29: 
   30: Boris Veytsman
   31: 
   32: =head1 $Id: updateindex.pl,v 1.1 2000/10/18 18:48:58 boris Exp $
   33: 
   34: =cut
   35: 
   36:     use strict;
   37: use vars qw($opt_m);
   38: 
   39: use Getopt::Std;
   40: use DBI;
   41: 
   42: MAIN: 
   43: {
   44:     getopts('m:') or die "Wrong options";
   45: 	my($source) = $opt_m || 'meta';
   46: 	my($depth, @depthId);
   47: 	my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "") 
   48: 		or die "Can't connect to DB chgk\n";
   49: 
   50: 	open INFD, $source or die "Can't open input file: $!\n";
   51: 	while (<INFD>) {
   52: 	    my $MetaId;
   53: 		s/^\[(\d*)\]\t//;
   54: 		$MetaId = $1;
   55: 		s/^(\t*)//;
   56: 		chomp;
   57: 		$depth = length($1);
   58: 		my $title = $dbh->quote($_);
   59: 		my $ParentId = ($depth) ? $depthId[$depth - 1] : 0;
   60: 		my ($sth) = $dbh->prepare("SELECT Id FROM Tournaments WHERE
   61: 			MetaId=$MetaId");
   62: 		$sth->execute;
   63: 		if ($sth->fetchrow) {
   64: 			print "$title is already in the DB!\n";
   65: 			next;
   66: 		}
   67: 		$sth = $dbh->prepare("INSERT INTO Tournaments
   68: 			(Title, ParentId, MetaId, Type) 
   69: 			VALUES ($title, $ParentId, $MetaId, 'ç')");
   70: 		$sth->execute;
   71: 		my $Id = $sth->{'mysql_insertid'};
   72: 		$depthId[$depth] = $Id;
   73: 	}
   74: 	$dbh->disconnect;
   75: }

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