X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bp_bin%2Fremove_mysql_tables;h=794ab0f9c36db3248f6da0414c68eefec04c2a41;hb=b75be26637f894573f1dbf5ebe31c5d651a4bb83;hp=fdf5bd287f78613d2aea83bb9b15f855cad57e77;hpb=e8e32d43d674573ff4a66fe77780cc18cb02d430;p=biopieces.git diff --git a/bp_bin/remove_mysql_tables b/bp_bin/remove_mysql_tables index fdf5bd2..794ab0f 100755 --- a/bp_bin/remove_mysql_tables +++ b/bp_bin/remove_mysql_tables @@ -1,6 +1,113 @@ #!/usr/bin/env perl +# Copyright (C) 2007-2009 Martin A. Hansen. + +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# http://www.gnu.org/copyleft/gpl.html + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# Remove MySQL database tables. + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + use warnings; use strict; +use Maasha::Biopieces; +use Maasha::Common; +use Maasha::SQL; +use Maasha::UCSC; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +my ( $options, $user, $password, $in, $out, $record, %table_hash, $dbh, $table ); + +$user = Maasha::Biopieces::biopiecesrc( "MYSQL_USER" ); +$password = Maasha::Biopieces::biopiecesrc( "MYSQL_PASSWORD" ); + +$options = Maasha::Biopieces::parse_options( + [ + { long => 'database', short => 'd', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, + { long => 'tables', short => 't', type => 'list', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'keys', short => 'k', type => 'list', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'user', short => 'u', type => 'string', mandatory => 'no', default => $user, allowed => undef, disallowed => undef }, + { long => 'password', short => 'p', type => 'string', mandatory => 'no', default => $password, allowed => undef, disallowed => undef }, + ] +); + +$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); +$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); + +Maasha::Common::error( qq(both --tables and --keys specified) ) if $options->{ "tables" } and $options->{ "keys" }; +Maasha::Common::error( qq(no --tables or --keys specified) ) if not $options->{ "tables" } and not $options->{ "keys" }; + +$options->{ "user" } ||= Maasha::UCSC::ucsc_get_user(); +$options->{ "password" } ||= Maasha::UCSC::ucsc_get_password(); + +map { $table_hash{ $_ } = 1 } @{ $options->{ 'tables' } }; + +while ( $record = Maasha::Biopieces::get_record( $in ) ) +{ + map { $table_hash{ $record->{ $_ } } = 1 } @{ $options->{ 'keys' } }; + + Maasha::Biopieces::put_record( $record, $out ) if not $options->{ 'no_stream' }; +} + +$dbh = Maasha::SQL::connect( $options->{ "database" }, $options->{ "user" }, $options->{ "password" } ); + +foreach $table ( sort keys %table_hash ) +{ + if ( Maasha::SQL::table_exists( $dbh, $table ) ) + { + print STDERR qq(Removing table "$table" from database "$options->{ 'database' }" ... ) if $options->{ 'verbose' }; + Maasha::SQL::delete_table( $dbh, $table ); + print STDERR "done.\n" if $options->{ 'verbose' }; + } + else + { + print STDERR qq(WARNING: table "$table" not found in database "$options->{ 'database' }\n"); + } +} + +Maasha::SQL::disconnect( $dbh ); + +Maasha::Biopieces::close_stream( $in ); +Maasha::Biopieces::close_stream( $out ); + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +BEGIN +{ + Maasha::Biopieces::status_set(); +} + + +END +{ + Maasha::Biopieces::status_log(); +} + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + -use Maasha::BioRun; +__END__