mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-04-26 01:02:25 +08:00
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:
+5
-9
@@ -2121,12 +2121,6 @@ sub fill_in_dsn {
|
|||||||
$dsn->{D} ||= $db;
|
$dsn->{D} ||= $db;
|
||||||
}
|
}
|
||||||
|
|
||||||
my %encoding_aliases = (
|
|
||||||
'utf-8' => 'utf8',
|
|
||||||
'iso-8859-1' => 'latin1',
|
|
||||||
'latin-1' => 'latin1',
|
|
||||||
);
|
|
||||||
|
|
||||||
sub get_dbh {
|
sub get_dbh {
|
||||||
my ( $self, $cxn_string, $user, $pass, $opts ) = @_;
|
my ( $self, $cxn_string, $user, $pass, $opts ) = @_;
|
||||||
$opts ||= {};
|
$opts ||= {};
|
||||||
@@ -2135,7 +2129,7 @@ sub get_dbh {
|
|||||||
RaiseError => 1,
|
RaiseError => 1,
|
||||||
PrintError => 0,
|
PrintError => 0,
|
||||||
ShowErrorStatement => 1,
|
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;
|
@{$defaults}{ keys %$opts } = values %$opts;
|
||||||
|
|
||||||
@@ -2203,8 +2197,7 @@ sub get_dbh {
|
|||||||
. ": $EVAL_ERROR";
|
. ": $EVAL_ERROR";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( my ($charset) = $cxn_string =~ m/charset=([-\w]+)/ ) {
|
if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
|
||||||
$charset = $encoding_aliases{lc($charset)} || $charset;
|
|
||||||
$sql = qq{/*!40101 SET NAMES "$charset"*/};
|
$sql = qq{/*!40101 SET NAMES "$charset"*/};
|
||||||
PTDEBUG && _d($dbh, ':', $sql);
|
PTDEBUG && _d($dbh, ':', $sql);
|
||||||
eval { $dbh->do($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
|
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.
|
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">.
|
See also L<"--[no]check-charset">.
|
||||||
|
|
||||||
=item --[no]check-charset
|
=item --[no]check-charset
|
||||||
|
|||||||
+2
-15
@@ -263,18 +263,6 @@ sub fill_in_dsn {
|
|||||||
$dsn->{D} ||= $db;
|
$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
|
# 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
|
# 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!
|
# connection or use $dbh->reconnect, or these things will not take place!
|
||||||
@@ -286,7 +274,7 @@ sub get_dbh {
|
|||||||
RaiseError => 1,
|
RaiseError => 1,
|
||||||
PrintError => 0,
|
PrintError => 0,
|
||||||
ShowErrorStatement => 1,
|
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;
|
@{$defaults}{ keys %$opts } = values %$opts;
|
||||||
|
|
||||||
@@ -364,8 +352,7 @@ sub get_dbh {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# 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]+)/ ) {
|
||||||
$charset = $encoding_aliases{lc($charset)} || $charset;
|
|
||||||
$sql = qq{/*!40101 SET NAMES "$charset"*/};
|
$sql = qq{/*!40101 SET NAMES "$charset"*/};
|
||||||
PTDEBUG && _d($dbh, ':', $sql);
|
PTDEBUG && _d($dbh, ':', $sql);
|
||||||
eval { $dbh->do($sql) };
|
eval { $dbh->do($sql) };
|
||||||
|
|||||||
+2
-2
@@ -554,7 +554,7 @@ my ($out, undef) = full_output(sub { $dp->get_dbh(@opts, {}) });
|
|||||||
like(
|
like(
|
||||||
$out,
|
$out,
|
||||||
qr/\QUnknown character set/,
|
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'");
|
$dp->prop('set-vars', "time_zoen='UTC'");
|
||||||
@@ -563,7 +563,7 @@ $dp->prop('set-vars', "time_zoen='UTC'");
|
|||||||
like(
|
like(
|
||||||
$out,
|
$out,
|
||||||
qr/\QUnknown system variable 'time_zoen'/,
|
qr/\QUnknown system variable 'time_zoen'/,
|
||||||
"get_dbh dies withg an unknown charset"
|
"get_dbh dies with an unknown system variable"
|
||||||
);
|
);
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ my $dbh = $sb->get_dbh_for('master');
|
|||||||
if ( !$dbh ) {
|
if ( !$dbh ) {
|
||||||
plan skip_all => 'Cannot connect to sandbox master';
|
plan skip_all => 'Cannot connect to sandbox master';
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
plan tests => 13;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $output;
|
my $output;
|
||||||
my $rows;
|
my $rows;
|
||||||
@@ -95,7 +92,7 @@ sub test_charset {
|
|||||||
) or diag($out);
|
) 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);
|
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.
|
# Done.
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
$sb->wipe_clean($dbh);
|
$sb->wipe_clean($dbh);
|
||||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||||
exit;
|
|
||||||
|
done_testing;
|
||||||
|
|||||||
Reference in New Issue
Block a user