Removed the charset munging and made a note in the pt-archiver docs that the only legal charsets are those known by MySQL

This commit is contained in:
Brian Fraser
2012-07-27 16:09:32 -03:00
parent 0d26097f31
commit 192f38498c
4 changed files with 17 additions and 32 deletions

View File

@@ -2121,12 +2121,6 @@ sub fill_in_dsn {
$dsn->{D} ||= $db;
}
my %encoding_aliases = (
'utf-8' => 'utf8',
'iso-8859-1' => 'latin1',
'latin-1' => 'latin1',
);
sub get_dbh {
my ( $self, $cxn_string, $user, $pass, $opts ) = @_;
$opts ||= {};
@@ -2135,7 +2129,7 @@ sub get_dbh {
RaiseError => 1,
PrintError => 0,
ShowErrorStatement => 1,
mysql_enable_utf8 => ($cxn_string =~ m/charset=utf-?8/i ? 1 : 0),
mysql_enable_utf8 => ($cxn_string =~ m/charset=utf8/i ? 1 : 0),
};
@{$defaults}{ keys %$opts } = values %$opts;
@@ -2203,8 +2197,7 @@ sub get_dbh {
. ": $EVAL_ERROR";
}
if ( my ($charset) = $cxn_string =~ m/charset=([-\w]+)/ ) {
$charset = $encoding_aliases{lc($charset)} || $charset;
if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
$sql = qq{/*!40101 SET NAMES "$charset"*/};
PTDEBUG && _d($dbh, ':', $sql);
eval { $dbh->do($sql) };
@@ -5116,6 +5109,9 @@ STDOUT to utf8, passes the mysql_enable_utf8 option to DBD::mysql, and runs SET
NAMES UTF8 after connecting to MySQL. Any other value sets binmode on STDOUT
without the utf8 layer, and runs SET NAMES after connecting to MySQL.
Note that only charsets as known by MySQL are recognized; So for example,
"UTF8" will work, but "UTF-8" will not.
See also L<"--[no]check-charset">.
=item --[no]check-charset

View File

@@ -263,18 +263,6 @@ sub fill_in_dsn {
$dsn->{D} ||= $db;
}
# MySQL won't resolve iso-8859-1 or latin-1 as latin1, while Perl would, so
# we hardcode the aliases here. The UTF-8 case is a bit different;
# MySQL doesn't really support UTF-8 in SET NAMES, instead using
# their own definition, which is constrained to codepoints 0..0xFFFF, so
# rightfully calls it something different: utf8. I'm not actually sure
# if the naming convention is intended or plain lucky on their part, though.
my %encoding_aliases = (
'utf-8' => 'utf8',
'iso-8859-1' => 'latin1',
'latin-1' => 'latin1',
);
# Actually opens a connection, then sets some things on the connection so it is
# the way the Maatkit tools will expect. Tools should NEVER open their own
# connection or use $dbh->reconnect, or these things will not take place!
@@ -286,7 +274,7 @@ sub get_dbh {
RaiseError => 1,
PrintError => 0,
ShowErrorStatement => 1,
mysql_enable_utf8 => ($cxn_string =~ m/charset=utf-?8/i ? 1 : 0),
mysql_enable_utf8 => ($cxn_string =~ m/charset=utf8/i ? 1 : 0),
};
@{$defaults}{ keys %$opts } = values %$opts;
@@ -364,8 +352,7 @@ sub get_dbh {
}
# Set character set and binmode on STDOUT.
if ( my ($charset) = $cxn_string =~ m/charset=([-\w]+)/ ) {
$charset = $encoding_aliases{lc($charset)} || $charset;
if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
$sql = qq{/*!40101 SET NAMES "$charset"*/};
PTDEBUG && _d($dbh, ':', $sql);
eval { $dbh->do($sql) };

View File

@@ -554,7 +554,7 @@ my ($out, undef) = full_output(sub { $dp->get_dbh(@opts, {}) });
like(
$out,
qr/\QUnknown character set/,
"get_dbh dies withg an unknown charset"
"get_dbh dies with an unknown charset"
);
$dp->prop('set-vars', "time_zoen='UTC'");
@@ -563,7 +563,7 @@ $dp->prop('set-vars', "time_zoen='UTC'");
like(
$out,
qr/\QUnknown system variable 'time_zoen'/,
"get_dbh dies withg an unknown charset"
"get_dbh dies with an unknown system variable"
);
# #############################################################################

View File

@@ -22,9 +22,6 @@ my $dbh = $sb->get_dbh_for('master');
if ( !$dbh ) {
plan skip_all => 'Cannot connect to sandbox master';
}
else {
plan tests => 13;
}
my $output;
my $rows;
@@ -95,7 +92,7 @@ sub test_charset {
) or diag($out);
}
for my $charset (qw(latin1 iso-8859-1 latin-1 utf8 UTF-8 UTF8 )) {
for my $charset (qw(latin1 utf8 UTF8 )) {
test_charset($charset);
}
@@ -112,11 +109,16 @@ my ($out) = full_output( sub {
},
);
like($out, qr/\QError setting NAMES to some_charset_that_doesn/, "..but an unknown charset fails");
like(
$out,
qr/\QError setting NAMES to some_charset_that_doesn/,
"..but an unknown charset fails"
);
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
exit;
done_testing;