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.2 2000/10/18 21:50:48 boris Exp $
33:
34: =cut
35:
36: use strict;
37: use vars qw($opt_i $opt_h);
38:
39: use Getopt::Std;
40: use DBI;
41:
42: MAIN:
43: {
44: my $USAGE="Usage: updateindex.pl -i indexfile\n";
45: getopts('hm:') or die $USAGE;
46: if ($opt_h) {
47: print $USAGE;
48: exit 0;
49: }
50: my($source) = $opt_i || 'index';
51: my($depth, @depthId);
52: my $filename;
53: my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "")
54: or die "Can't connect to DB chgk\n";
55:
56: open INFD, $source or die "Can't open input file: $!\n";
57: while (<INFD>) {
58: chomp;
59: s/
//;
60: next if (/^\s*$/);
61: if (s/^(\w*)//) { # File found
62: $filename = $1;
63: $depth = -1;
64: } else { # Group found
65: undef $filename;
66: $depth = -2;
67: }
68: s/^(\t*)//;
69: $depth += length($1);
70: if ($depth < 0) {
71: die "Wrong line $_\n";
72: }
73: s/^\s*//;
74: s/\s$//;
75: my $title = $dbh->quote($_);
76: my $ParentId = ($depth) ? $depthId[$depth - 1] : 0;
77: my $sth;
78: my $type;
79: if (defined $filename) {
80: $type=$dbh->quote('þ');
81: $filename = $dbh->quote($filename);
82: $sth = $dbh->prepare("SELECT Id FROM Tournaments
83: WHERE FileName=$filename");
84: $sth->execute;
85: if ($sth->fetchrow) {
86: print "$filename is already in the DB!\n";
87: next;
88: }
89: $sth = $dbh->prepare("INSERT INTO Tournaments
90: (Title, ParentId, FileName, Type)
91: VALUES ($title, $ParentId, $filename, $type;)");
92: $sth->execute;
93: } else {
94: $sth->execute;
95: $sth = $dbh->prepare("SELECT Id FROM Tournaments
96: WHERE Title=$title");
97: $type=$dbh->quote('ç');
98: if ($sth->fetchrow) {
99: print "$title is already in the DB!\n";
100: next;
101: }
102: $sth = $dbh->prepare("INSERT INTO Tournaments
103: (Title, ParentId, Type)
104: VALUES ($title, $ParentId, $type;)");
105: $sth->execute;
106: my $Id = $sth->{'mysql_insertid'};
107: $depthId[$depth] = $Id;
108: }
109:
110: }
111: $dbh->disconnect;
112: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>