DSNParser.pm: Work around MySQL not resolving encodings sanely.

For some reason, MySQL won't resolve iso-8859-1 or latin-1 as latin1,
and will die if you try to use through in, e.g., SET NAMES.
This commit makes DSNParser resolve those cases on its own
before calling SET NAMES.
This commit is contained in:
Brian Fraser
2012-07-23 01:11:49 -03:00
parent 02c6421a25
commit 61a65fcdbd
3 changed files with 52 additions and 26 deletions

View File

@@ -23,7 +23,7 @@ if ( !$dbh ) {
plan skip_all => 'Cannot connect to sandbox master';
}
else {
plan tests => 12;
plan tests => 13;
}
my $output;
@@ -80,25 +80,28 @@ sub test_charset {
$sb->load_file('master', 't/pt-archiver/samples/table1.sql');
local $@;
eval {
my ($out, $exit_val) = full_output( sub {
pt_archiver::main("-c", "b,c", qw(--where 1=1 --header),
"--source", "D=test,t=table_1,F=$cnf",
'--file', '/tmp/%Y-%m-%d-%D_%H:%i:%s.%t',
'--no-check-charset',
'--charset', $charset,
);
};
});
ok !$@, "--charset $charset works";
is($exit_val,
0,
"--charset $charset works"
) or diag($out);
}
for my $charset (qw(latin1 iso-8859-1 utf8 UTF-8 )) {
for my $charset (qw(latin1 iso-8859-1 latin-1 utf8 UTF-8 UTF8 )) {
test_charset($charset);
}
my $warning;
local $SIG{__WARN__} = sub { $warning .= shift };
my $out = output( sub {
my ($out) = full_output( sub {
$sb->load_file('master', 't/pt-archiver/samples/table1.sql');
pt_archiver::main("-c", "b,c", qw(--where 1=1 --header),
"--source", "D=test,t=table_1,F=$cnf",
@@ -109,8 +112,7 @@ my $out = output( sub {
},
);
like($out, qr/\QCannot open :encoding(some_chars/, "..but an unknown charset fails");
like($warning, qr/Cannot find encoding/, "..and throws a useful warning");
like($out, qr/\QError setting NAMES to some_charset_that_doesn/, "..but an unknown charset fails");
# #############################################################################
# Done.