Don't re-use same db in use_repl_db().

This commit is contained in:
Daniel Nichter
2011-09-12 10:30:40 -06:00
parent f0e87228dd
commit 5281c76aaf

View File

@@ -5233,6 +5233,9 @@ sub check_repl_table {
# won't pass a tbl arg because they're just doing something to
# the --replicate table.
# See http://code.google.com/p/maatkit/issues/detail?id=982
{
my $current_db;
sub use_repl_db {
my ( %args ) = @_;
my @required_args = qw(dbh repl_table OptionParser Quoter);
@@ -5255,25 +5258,29 @@ sub use_repl_db {
$db = $o->get('replicate-database') if $o->get('replicate-database');
}
eval {
my $sql = "USE " . $q->quote($db);
MKDEBUG && _d($sql);
$dbh->do($sql);
};
if ( $EVAL_ERROR ) {
# Report which option db really came from.
my $opt = $o->get('replicate-database') ? "--replicate-database"
: "--replicate database";
if ( $EVAL_ERROR =~ m/unknown database/i ) {
die "$opt `$db` does not exist: $EVAL_ERROR";
}
else {
die "Error using $opt `$db`: $EVAL_ERROR";
if ( !$current_db || $current_db ne $db ) {
eval {
my $sql = "USE " . $q->quote($db);
MKDEBUG && _d($sql);
$dbh->do($sql);
};
if ( $EVAL_ERROR ) {
# Report which option db really came from.
my $opt = $o->get('replicate-database') ? "--replicate-database"
: "--replicate database";
if ( $EVAL_ERROR =~ m/unknown database/i ) {
die "$opt `$db` does not exist: $EVAL_ERROR";
}
else {
die "Error using $opt `$db`: $EVAL_ERROR";
}
}
$current_db = $db;
}
return;
}
}
sub create_repl_table {
my ( %args ) = @_;