#!/usr/local/bin/perl -w
=head1 NAME
renamefile.pl - renaming file in database
=head1 SYNOPSIS
renamefile.pl I<source> I<target>
=head1 DESCRIPTION
The script will rename source to target in the database
=head1 BUGS
The database, user and password are hardcoded.
=head1 SEE ALSO
createindex.pl(1), updatedb.pl(1), updateindex.pl(1), deletefiles.pl(1)
=head1 AUTHOR
Boris Veytsman
=head1 $Id: renamefile.pl,v 1.2 2001/07/28 21:39:47 boris Exp $
=cut
use strict;
use DBI;
MAIN:
{
my $USAGE="Usage: renamefile.pl source target\n";
if (scalar @ARGV <=> 2) {
die $USAGE;
}
my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "")
or die "Can't connect to DB chgk\n";
my ($source,$target)=@ARGV;
my $sth=$dbh->prepare("
select Title from Tournaments where
Type='þ' and FileName='$source'");
$sth->execute;
if(!$sth->rows) {
print STDERR "There is no file $source in the database\n";
$sth->finish;
$dbh->disconnect;
exit 1;
}
my ($Title)=$sth->fetchrow;
$sth=$dbh->prepare("
select Title from Tournaments where
Type='þ' and FileName='$target'");
$sth->execute;
if($sth->rows) {
($Title)=$sth->fetchrow;
print STDERR "The file $source already exists. The title is $Title\n";
$sth->finish;
$dbh->disconnect;
exit 1;
}
$sth=$dbh->prepare("
update Tournaments set FileName='$target' where Filename='$source'");
$sth->execute;
$dbh->disconnect;
exit 0;
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>