From 484274d8ba5d6c87028db0939bc2e19002e028a7 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Sat, 3 Aug 2013 12:11:56 -0700 Subject: [PATCH] Fix get_tables() for LOAD DATA. --- lib/QueryParser.pm | 9 +++++++-- t/lib/QueryParser.t | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/QueryParser.pm b/lib/QueryParser.pm index 5b3f1633..d1eeb8f9 100644 --- a/lib/QueryParser.pm +++ b/lib/QueryParser.pm @@ -98,7 +98,7 @@ sub get_tables { # These keywords may appear between UPDATE or SELECT and the table refs. # They need to be removed so that they are not mistaken for tables. - $query =~ s/ (?:LOW_PRIORITY|IGNORE|STRAIGHT_JOIN|DELAYED) / /ig; + $query =~ s/(?:LOW_PRIORITY|IGNORE|STRAIGHT_JOIN|DELAYED)\s+/ /ig; # Another special case: LOCK TABLES tbl [[AS] alias] READ|WRITE, etc. # We strip the LOCK TABLES stuff and append "FROM" to fake a SELECT @@ -116,11 +116,16 @@ sub get_tables { # INSERT and REPLACE without INTO # https://bugs.launchpad.net/percona-toolkit/+bug/984053 - if ( $query =~ m/\A\s*(?:INSERT|REPLACE)\s+(?!INTO)/i ) { + if ( $query =~ m/\A\s*(?:INSERT|REPLACE)(?!\s+INTO)/i ) { # Add INTO so the reset of the code work as usual. $query =~ s/\A\s*((?:INSERT|REPLACE))\s+/$1 INTO /i; } + if ( $query =~ m/\A\s*LOAD DATA/i ) { + my ($tbl) = $query =~ m/INTO TABLE\s+(\S+)/i; + return $tbl; + } + my @tables; foreach my $tbls ( $query =~ m/$tbl_regex/gio ) { PTDEBUG && _d('Match tables:', $tbls); diff --git a/t/lib/QueryParser.t b/t/lib/QueryParser.t index 3f453b4e..dc3a2cf4 100644 --- a/t/lib/QueryParser.t +++ b/t/lib/QueryParser.t @@ -828,6 +828,12 @@ is_deeply( [qw(t1 t2)], 'get_tables works for lowercased LOCK TABLES', ); +is_deeply( + [ $qp->get_tables("LOAD DATA INFILE '/tmp/foo.txt' INTO TABLE db.tbl") ], + [qw(db.tbl)], + "LOAD DATA db.tbl" +); + # ############################################################################# # Done. # #############################################################################