diff --git a/lib/TableParser.pm b/lib/TableParser.pm index 37834f38..f9cbbfc1 100644 --- a/lib/TableParser.pm +++ b/lib/TableParser.pm @@ -412,7 +412,8 @@ sub get_keys { # will report its index as USING HASH even when this is not supported. # The true type should be BTREE. See # http://bugs.mysql.com/bug.php?id=22632 - if ( $engine !~ m/MEMORY|HEAP/ ) { + # If ANSI quoting is in effect, we may not know the engine at all. + if ( !$engine || $engine !~ m/MEMORY|HEAP/ ) { $key =~ s/USING HASH/USING BTREE/; } @@ -454,7 +455,7 @@ sub get_keys { }; # Find clustered key (issue 295). - if ( $engine =~ m/InnoDB/i && !$clustered_key ) { + if ( ($engine || '') =~ m/InnoDB/i && !$clustered_key ) { my $this_key = $keys->{$name}; if ( $this_key->{name} eq 'PRIMARY' ) { $clustered_key = 'PRIMARY'; diff --git a/lib/TableSyncChunk.pm b/lib/TableSyncChunk.pm index 9d8eaa55..65aea35e 100644 --- a/lib/TableSyncChunk.pm +++ b/lib/TableSyncChunk.pm @@ -182,7 +182,7 @@ sub set_checksum_queries { sub prepare_sync_cycle { my ( $self, $host ) = @_; - my $sql = 'SET @crc := "", @cnt := 0'; + my $sql = q{SET @crc := '', @cnt := 0}; PTDEBUG && _d($sql); $host->{dbh}->do($sql); return; diff --git a/lib/TableSyncNibble.pm b/lib/TableSyncNibble.pm index 9eeab295..95341ba6 100644 --- a/lib/TableSyncNibble.pm +++ b/lib/TableSyncNibble.pm @@ -182,7 +182,7 @@ sub set_checksum_queries { sub prepare_sync_cycle { my ( $self, $host ) = @_; - my $sql = 'SET @crc := "", @cnt := 0'; + my $sql = q{SET @crc := '', @cnt := 0}; PTDEBUG && _d($sql); $host->{dbh}->do($sql); return; diff --git a/lib/TableUsage.pm b/lib/TableUsage.pm index c2bb1139..acc349bb 100644 --- a/lib/TableUsage.pm +++ b/lib/TableUsage.pm @@ -870,7 +870,27 @@ sub _explain_query { . "Message: " . ($warning->{message} || "") . "\n"; } - return $warning->{message}; + return $self->ansi_to_legacy($warning->{message}); +} + +# Translates ANSI quoting into legacy backtick-quoting. +# TODO: use TableParser::ansi_to_legacy instead (this code is copy/paste) +my $ansi_quote_re = qr/" [^"]* (?: "" [^"]* )* (?<=.) "/ismx; +sub ansi_to_legacy { + my ($self, $sql) = @_; + $sql =~ s/($ansi_quote_re)/ansi_quote_replace($1)/ge; + return $sql; +} + +# Translates a single string from ANSI quoting into legacy quoting by +# un-doubling embedded double-double quotes, doubling backticks, and replacing +# the delimiters. TODO: this is a copy-paste of TableParser.pm's code +sub ansi_quote_replace { + my ($val) = @_; + $val =~ s/^"|"$//g; + $val =~ s/`/``/g; + $val =~ s/""/"/g; + return "`$val`"; } sub _get_tables { diff --git a/t/pt-table-checksum/samples/issue_602.sql b/t/pt-table-checksum/samples/issue_602.sql index 97dfd0f6..53eac1f9 100644 --- a/t/pt-table-checksum/samples/issue_602.sql +++ b/t/pt-table-checksum/samples/issue_602.sql @@ -7,16 +7,16 @@ create table t ( b datetime not null, key (b) ); -insert into t VALUES (1, "2010-05-09 00:00:00"); -insert into t VALUES (2, "2010-05-08 00:00:00"); -insert into t VALUES (3, "2010-05-07 00:00:00"); -insert into t VALUES (4, "2010-05-06 00:00:00"); -insert into t VALUES (5, "2010-05-05 00:00:00"); -insert into t VALUES (6, "2010-05-04 00:00:00"); -insert into t VALUES (7, "2010-05-03 00:00:00"); -insert into t VALUES (8, "2010-05-02 00:00:00"); -insert into t VALUES (9, "2010-05-01 00:00:00"); -insert into t VALUES (10, "2010-04-30 00:00:00"); +insert into t VALUES (1, '2010-05-09 00:00:00'); +insert into t VALUES (2, '2010-05-08 00:00:00'); +insert into t VALUES (3, '2010-05-07 00:00:00'); +insert into t VALUES (4, '2010-05-06 00:00:00'); +insert into t VALUES (5, '2010-05-05 00:00:00'); +insert into t VALUES (6, '2010-05-04 00:00:00'); +insert into t VALUES (7, '2010-05-03 00:00:00'); +insert into t VALUES (8, '2010-05-02 00:00:00'); +insert into t VALUES (9, '2010-05-01 00:00:00'); +insert into t VALUES (10, '2010-04-30 00:00:00'); -- invalid datetime insert into t VALUES (11, '2010-00-09 00:00:00' ); @@ -29,11 +29,11 @@ create table t2 ( b datetime not null, key (b) ); -insert into t2 VALUES (1, "2010-00-01 00:00:01"); -insert into t2 VALUES (2, "2010-00-02 00:00:02"); -insert into t2 VALUES (3, "2010-00-03 00:00:03"); -insert into t2 VALUES (4, "2010-00-04 00:00:04"); -insert into t2 VALUES (5, "2010-00-05 00:00:05"); -insert into t2 VALUES (6, "2010-00-06 00:00:06"); -insert into t2 VALUES (7, "2010-01-07 00:00:07"); -insert into t2 VALUES (7, "2010-01-08 00:00:08"); +insert into t2 VALUES (1, '2010-00-01 00:00:01'); +insert into t2 VALUES (2, '2010-00-02 00:00:02'); +insert into t2 VALUES (3, '2010-00-03 00:00:03'); +insert into t2 VALUES (4, '2010-00-04 00:00:04'); +insert into t2 VALUES (5, '2010-00-05 00:00:05'); +insert into t2 VALUES (6, '2010-00-06 00:00:06'); +insert into t2 VALUES (7, '2010-01-07 00:00:07'); +insert into t2 VALUES (7, '2010-01-08 00:00:08');