File:  [Local Repository] / db / prgsrc / updatem.pl
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Tue Oct 17 01:53:44 2000 UTC (23 years, 7 months ago) by boris
Branches: MAIN
CVS tags: HEAD
Changed insertid to mysql_insertid

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

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