X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bp_bin%2Fremove_mysql_tables;h=794ab0f9c36db3248f6da0414c68eefec04c2a41;hb=5de6112b70b59420b245ce636a8b2e3c90acbe00;hp=39a2428abb6f0ea325a73b69ff2084fe904fb137;hpb=f7e5c1b54c562cc1b25fe419cacd4da9ac01f129;p=biopieces.git diff --git a/bp_bin/remove_mysql_tables b/bp_bin/remove_mysql_tables deleted file mode 120000 index 39a2428..0000000 --- a/bp_bin/remove_mysql_tables +++ /dev/null @@ -1 +0,0 @@ -../code_perl/Maasha/bin/remove_mysql_tables \ No newline at end of file diff --git a/bp_bin/remove_mysql_tables b/bp_bin/remove_mysql_tables new file mode 100755 index 0000000..794ab0f --- /dev/null +++ b/bp_bin/remove_mysql_tables @@ -0,0 +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(); +} + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +__END__