#!/usr/bin/perl # Copyright 2004 Jerzy Wachowiak use strict; use warnings; use DBI; use Getopt::Std; # Option retrival getopts( "msht:d:u:p:" ); our ( $opt_m, $opt_s, $opt_t ); our( $opt_d, $opt_u, $opt_p, $opt_h ); unless ( $opt_m or $opt_s or $opt_t or $opt_h or $opt_d ) { $opt_h = 1 }; if ( defined( $opt_m ) and defined( $opt_s ) ){ undef $opt_m; undef $opt_s }; if ( defined( $opt_h ) ){ print <1, RaiseError=>1, AutoCommit => 0 ); my $dbh = DBI->connect( $DBIdriver.$database, $DBIuser,$DBIpassword, \%attr ); my ( $sqlcommand, $sth, @row, $srv, $mrv ); # Option delete statistics: if ( $opt_s ){ $sqlcommand = "delete from statistics where thread = '$opt_t' "; $sth = $dbh->prepare( $sqlcommand ); $srv = $sth->execute(); $dbh->commit(); if ( $srv == 0 ) { $srv = 0 }; $mrv = 0; print "$mrv; $srv\n" } # Option delete messages if ( $opt_m ){ $sqlcommand = "delete from messages where thread = '$opt_t' "; $sth = $dbh->prepare( $sqlcommand ); $mrv = $sth->execute(); $dbh->commit(); if ( $mrv == 0 ) { $mrv = 0 }; $srv = 0; print "$mrv; $srv\n" } # All messages and threads should be deleted: if ( !defined( $opt_m ) and !defined( $opt_s ) ){ eval { $sqlcommand = "delete from statistics where thread = '$opt_t' "; $sth = $dbh->prepare( $sqlcommand ); $srv = $sth->execute(); $sqlcommand = "delete from messages where thread = '$opt_t' "; $sth = $dbh->prepare( $sqlcommand ); $mrv = $sth->execute(); $dbh->commit() }; if ( $@ ) { $dbh->rollback() } else { if ( $srv == 0 ) { $srv = 0 }; if ( $mrv == 0 ) { $mrv = 0 }; print "$mrv; $srv\n"; } } $dbh->disconnect(); exit 0