Annotation of db/prgsrc/updatem.pl, revision 1.1
1.1 ! boris 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: mkdb.pl,v 1.2 2000/10/17 01:31:27 boris Exp $
! 26:
! 27: =cut
! 28:
! 29: use DBI;
! 30:
! 31: MAIN:
! 32: {
! 33:
! 34: my($source) = 'meta';
! 35: my($depth, @depthId);
! 36: my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "")
! 37: or die "Can't connect to DB chgk\n";
! 38:
! 39: open INFD, $source or die "Can't open input file: $!\n";
! 40: while (<INFD>) {
! 41: s/^\[(\d*)\]\t//;
! 42: $MetaId = $1;
! 43: s/^(\t*)//;
! 44: chomp;
! 45: $depth = length($1);
! 46: $title = $dbh->quote($_);
! 47: $ParentId = ($depth) ? $depthId[$depth - 1] : 0;
! 48: my ($sth) = $dbh->prepare("SELECT Id FROM Tournaments WHERE
! 49: MetaId=$MetaId");
! 50: $sth->execute;
! 51: if ($sth->fetchrow) {
! 52: print "$title is already in the DB!\n";
! 53: next;
! 54: }
! 55: $sth = $dbh->prepare("INSERT INTO Tournaments
! 56: (Title, ParentId, MetaId, Type)
! 57: VALUES ($title, $ParentId, $MetaId, 'ç')");
! 58: $sth->execute;
! 59: $Id = $sth->{insertid};
! 60: $depthId[$depth] = $Id;
! 61: }
! 62: $dbh->disconnect;
! 63: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>