Annotation of db/prgsrc/updatem.pl, revision 1.3

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: 
1.3     ! boris      25: =head1 $Id: updatem.pl,v 1.2 2000/10/17 01:47:34 boris Exp boris $
1.1       boris      26: 
                     27: =cut
                     28: 
1.2       boris      29:     use strict;
                     30: use vars qw($opt_m);
                     31: 
                     32: use Getopt::Std;
1.1       boris      33: use DBI;
                     34: 
                     35: MAIN: 
                     36: {
1.2       boris      37:     getopts('m:') or die "Wrong options";
                     38:        my($source) = $opt_m || 'meta';
1.1       boris      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>) {
1.2       boris      45:            my $MetaId;
1.1       boris      46:                s/^\[(\d*)\]\t//;
                     47:                $MetaId = $1;
                     48:                s/^(\t*)//;
                     49:                chomp;
                     50:                $depth = length($1);
1.2       boris      51:                my $title = $dbh->quote($_);
                     52:                my $ParentId = ($depth) ? $depthId[$depth - 1] : 0;
1.1       boris      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;
1.3     ! boris      64:                my $Id = $sth->{'mysql_insertid'};
1.1       boris      65:                $depthId[$depth] = $Id;
                     66:        }
                     67:        $dbh->disconnect;
                     68: }

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