From c375fd068b1ed4a6a83d632e6e22b7673b269ff7 Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Mon, 14 Aug 2017 21:01:30 -0300 Subject: [PATCH] PT-193 Fixed regex in TableParser TableParser's parse function was failing while trying to lowercase column names in the provided 'SHOW CREATE TABLE'. The problem was it was trying to lowercase everything between backticks but lines like these: `field_name` int comment "here is a ` in the comment" `second_field_name` int made the original regex to fail, matching `in the coment"` as an expression to be lowercased while second_file_name was considered as outside backticks. --- lib/TableParser.pm | 2 +- t/lib/TableParser.t | 26 +++++++++++++++++++ .../issue_pt-193_backtick_in_col_comments.sql | 6 +++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 t/lib/samples/issue_pt-193_backtick_in_col_comments.sql diff --git a/lib/TableParser.pm b/lib/TableParser.pm index 2f7521f6..4b5904bb 100644 --- a/lib/TableParser.pm +++ b/lib/TableParser.pm @@ -145,7 +145,7 @@ sub parse { # Lowercase identifiers to avoid issues with case-sensitivity in Perl. # (Bug #1910276). - $ddl =~ s/(`[^`]+`)/\L$1/g; + $ddl =~ s/(`[^`\n]+`)/\L$1/gm; my $engine = $self->get_engine($ddl); diff --git a/t/lib/TableParser.t b/t/lib/TableParser.t index 52bdd52b..8a063ee6 100644 --- a/t/lib/TableParser.t +++ b/t/lib/TableParser.t @@ -806,6 +806,32 @@ is_deeply( 'issue with pairing backticks in column comments (issue 330)' ); + +$tbl = $tp->parse( load_file('t/lib/samples/issue_pt-193_backtick_in_col_comments.sql') ); +is_deeply( + $tbl, + { cols => [qw(id f22abcde f23abc)], + col_posn => { id => 0, f22abcde => 1, f23abc => 2 }, + is_col => { id => 1, f22abcde => 1, f23abc => 1 }, + is_autoinc => { id => 1, f22abcde => 0, f23abc => 0 }, + null_cols => [qw(f22abcde)], + is_nullable => { f22abcde => 1}, + clustered_key => undef, + keys => {}, + defs => { id => " `id` int(11) NOT NULL AUTO_INCREMENT", + "f22abcde" => " `f22abcde` int(10) unsigned DEFAULT NULL COMMENT 'xxx`XXx'", + "f23abc" => " `f23abc` int(10) unsigned NOT NULL DEFAULT '255' COMMENT \"`yyy\"" + }, + numeric_cols => [qw(id f22abcde f23abc)], + is_numeric => { id => 1, f22abcde => 1, f23abc => 1 }, + engine => 'InnoDB', + type_for => { id => 'int', f22abcde => 'int', f23abc => 'int' }, + name => 't3', + charset => 'latin1', + }, + 'issue with pairing backticks in column comments (issue 330)' +); + # ############################################################################# # Issue 170: mk-parallel-dump dies when table-status Data_length is NULL # ############################################################################# diff --git a/t/lib/samples/issue_pt-193_backtick_in_col_comments.sql b/t/lib/samples/issue_pt-193_backtick_in_col_comments.sql new file mode 100644 index 00000000..e6f123d3 --- /dev/null +++ b/t/lib/samples/issue_pt-193_backtick_in_col_comments.sql @@ -0,0 +1,6 @@ +Create Table: CREATE TABLE `t3` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `f22aBcDe` int(10) unsigned DEFAULT NULL COMMENT 'xxx`XXx', + `f23aBc` int(10) unsigned NOT NULL DEFAULT '255' COMMENT "`yyy", + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1)