PT-2279 - Option --charset is confusing when set to utf8mb4

- Added pattern check for utf8 character set instead of eq
- Added test cases
This commit is contained in:
Sveta Smirnova
2023-11-06 23:26:54 +03:00
parent 8e4824813f
commit f0af7114e7
3 changed files with 100 additions and 2 deletions

View File

@@ -6786,8 +6786,8 @@ sub main {
}
my $charset = $got_charset || '';
if ($charset eq 'utf8') {
$charset = ":$charset";
if ($charset =~ m/utf8/) {
$charset = ":utf8";
}
elsif ($charset) {
eval { require Encode }

80
t/pt-archiver/pt-2279.t Normal file
View File

@@ -0,0 +1,80 @@
#!/usr/bin/env perl
BEGIN {
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More;
use charnames ':full';
use PerconaTest;
use Sandbox;
require "$trunk/bin/pt-archiver";
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $dbh = $sb->get_dbh_for('master');
if ( !$dbh ) {
plan skip_all => 'Cannot connect to sandbox master';
}
my $output;
my $cnf = "/tmp/12345/my.sandbox.cnf";
my $cmd = "$trunk/bin/pt-archiver";
$sb->wipe_clean($dbh);
$sb->create_dbs($dbh, ['test']);
# Test --bulk-insert
$sb->load_file('master', 't/pt-archiver/samples/pt-2279.sql');
$output = output(
sub { pt_archiver::main(qw(--limit 50 --bulk-insert),
qw(--bulk-delete --where 1=1 --statistics --charset utf8mb4),
'--source', "L=1,D=test,t=table_1,F=$cnf",
'--dest', "t=table_1_dest") },
);
unlike(
$output,
qr/Cannot find encoding "utf8mb4"/,
'Bulk insert does not fail due to missing utf8mb4'
) or diag($output);
# Test --file
$sb->load_file('master', 't/pt-archiver/samples/pt-2279.sql');
$output = output(
sub { pt_archiver::main(qw(--limit 50),
qw(--where 1=1 --statistics --charset utf8mb4),
'--source', "L=1,D=test,t=table_1,F=$cnf",
'--file', '/tmp/%Y-%m-%d-%D_%H:%i:%s.%t') },
);
unlike(
$output,
qr/Cannot find encoding "utf8mb4"/,
'Destination file does not fail due to missing utf8mb4'
) or diag($output);
unlike(
$output,
qr/Cannot open :encoding(utf8mb4)/,
'Destination file can be read if encodin utf8mb4 is used'
) or diag($output);
# #############################################################################
# Done.
# #############################################################################
diag(`rm -f /tmp/*.table_1`);
$sb->wipe_clean($dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
done_testing;
exit;

View File

@@ -0,0 +1,18 @@
DROP TABLE IF EXISTS test.table_1;
DROP TABLE IF EXISTS test.table_1_dest;
SET NAMES utf8mb4;
CREATE TABLE test.table_1 (
id int(11) NOT NULL,
c1 varchar(20) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO test.table_1 VALUES(1, 'I love MySQL! 🐬');
CREATE TABLE test.table_1_dest (
id int(11) NOT NULL,
c1 varchar(10) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;