Fix for 1078887: Don't clobber the sql_mode set by the script with set-vars

This commit is contained in:
Brian Fraser
2012-12-03 00:43:10 -03:00
parent e71d3adb96
commit d98f8e04c9
2 changed files with 33 additions and 12 deletions

View File

@@ -343,18 +343,6 @@ sub get_dbh {
die "Error getting the current SQL_MODE: $EVAL_ERROR"; die "Error getting the current SQL_MODE: $EVAL_ERROR";
} }
$sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
. '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO'
. ($sql_mode ? ",$sql_mode" : '')
. '\'*/';
PTDEBUG && _d($dbh, $sql);
eval { $dbh->do($sql) };
if ( $EVAL_ERROR ) {
die "Error setting SQL_QUOTE_SHOW_CREATE, SQL_MODE"
. ($sql_mode ? " and $sql_mode" : '')
. ": $EVAL_ERROR";
}
# Set character set and binmode on STDOUT. # Set character set and binmode on STDOUT.
if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
$sql = qq{/*!40101 SET NAMES "$charset"*/}; $sql = qq{/*!40101 SET NAMES "$charset"*/};
@@ -381,6 +369,20 @@ sub get_dbh {
die "Error setting $var: $EVAL_ERROR"; die "Error setting $var: $EVAL_ERROR";
} }
} }
# Do this after set-vars so a user-set sql_mode doesn't clobber it; See
# https://bugs.launchpad.net/percona-toolkit/+bug/1078887
$sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
. '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO'
. ($sql_mode ? ",$sql_mode" : '')
. '\'*/';
PTDEBUG && _d($dbh, $sql);
eval { $dbh->do($sql) };
if ( $EVAL_ERROR ) {
die "Error setting SQL_QUOTE_SHOW_CREATE, SQL_MODE"
. ($sql_mode ? " and $sql_mode" : '')
. ": $EVAL_ERROR";
}
} }
PTDEBUG && _d('DBH info: ', PTDEBUG && _d('DBH info: ',

View File

@@ -570,6 +570,24 @@ like(
); );
$dp->prop('set-vars', undef); $dp->prop('set-vars', undef);
# #############################################################################
# Bug 1078887: Don't clobber the sql_mode set by the script with set-vars
# https://bugs.launchpad.net/percona-toolkit/+bug/1078887
# #############################################################################
$dp->prop('set-vars', "sql_mode=ANSI_QUOTES");
my $sql_mode_dbh = $dp->get_dbh($dp->get_cxn_params($dsn), {});
my (undef, $sql_mode) = $sql_mode_dbh->selectrow_array(q{SHOW VARIABLES LIKE 'sql\_mode'});
like(
$sql_mode,
qr/NO_AUTO_VALUE_ON_ZERO/,
"Bug 1078887: --set-vars doesn't clover the sql_mode set by DSNParser"
);
$sql_mode_dbh->disconnect();
# ############################################################################# # #############################################################################
# LOAD DATA LOCAL INFILE broken in some platforms # LOAD DATA LOCAL INFILE broken in some platforms
# https://bugs.launchpad.net/percona-toolkit/+bug/821715 # https://bugs.launchpad.net/percona-toolkit/+bug/821715
@@ -610,3 +628,4 @@ SKIP: {
# Done. # Done.
# ############################################################################# # #############################################################################
done_testing; done_testing;