Some fixes for ANSI SQL quotes

This commit is contained in:
Baron Schwartz
2012-06-07 14:53:47 -04:00
parent db8f834164
commit 8e9dfeec68
5 changed files with 44 additions and 23 deletions

View File

@@ -412,7 +412,8 @@ sub get_keys {
# will report its index as USING HASH even when this is not supported. # will report its index as USING HASH even when this is not supported.
# The true type should be BTREE. See # The true type should be BTREE. See
# http://bugs.mysql.com/bug.php?id=22632 # 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/; $key =~ s/USING HASH/USING BTREE/;
} }
@@ -454,7 +455,7 @@ sub get_keys {
}; };
# Find clustered key (issue 295). # Find clustered key (issue 295).
if ( $engine =~ m/InnoDB/i && !$clustered_key ) { if ( ($engine || '') =~ m/InnoDB/i && !$clustered_key ) {
my $this_key = $keys->{$name}; my $this_key = $keys->{$name};
if ( $this_key->{name} eq 'PRIMARY' ) { if ( $this_key->{name} eq 'PRIMARY' ) {
$clustered_key = 'PRIMARY'; $clustered_key = 'PRIMARY';

View File

@@ -182,7 +182,7 @@ sub set_checksum_queries {
sub prepare_sync_cycle { sub prepare_sync_cycle {
my ( $self, $host ) = @_; my ( $self, $host ) = @_;
my $sql = 'SET @crc := "", @cnt := 0'; my $sql = q{SET @crc := '', @cnt := 0};
PTDEBUG && _d($sql); PTDEBUG && _d($sql);
$host->{dbh}->do($sql); $host->{dbh}->do($sql);
return; return;

View File

@@ -182,7 +182,7 @@ sub set_checksum_queries {
sub prepare_sync_cycle { sub prepare_sync_cycle {
my ( $self, $host ) = @_; my ( $self, $host ) = @_;
my $sql = 'SET @crc := "", @cnt := 0'; my $sql = q{SET @crc := '', @cnt := 0};
PTDEBUG && _d($sql); PTDEBUG && _d($sql);
$host->{dbh}->do($sql); $host->{dbh}->do($sql);
return; return;

View File

@@ -870,7 +870,27 @@ sub _explain_query {
. "Message: " . ($warning->{message} || "") . "\n"; . "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 { sub _get_tables {

View File

@@ -7,16 +7,16 @@ create table t (
b datetime not null, b datetime not null,
key (b) key (b)
); );
insert into t VALUES (1, "2010-05-09 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 (2, '2010-05-08 00:00:00');
insert into t VALUES (3, "2010-05-07 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 (4, '2010-05-06 00:00:00');
insert into t VALUES (5, "2010-05-05 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 (6, '2010-05-04 00:00:00');
insert into t VALUES (7, "2010-05-03 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 (8, '2010-05-02 00:00:00');
insert into t VALUES (9, "2010-05-01 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 (10, '2010-04-30 00:00:00');
-- invalid datetime -- invalid datetime
insert into t VALUES (11, '2010-00-09 00:00:00' ); insert into t VALUES (11, '2010-00-09 00:00:00' );
@@ -29,11 +29,11 @@ create table t2 (
b datetime not null, b datetime not null,
key (b) key (b)
); );
insert into t2 VALUES (1, "2010-00-01 00:00:01"); 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 (2, '2010-00-02 00:00:02');
insert into t2 VALUES (3, "2010-00-03 00:00:03"); 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 (4, '2010-00-04 00:00:04');
insert into t2 VALUES (5, "2010-00-05 00:00:05"); 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 (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-07 00:00:07');
insert into t2 VALUES (7, "2010-01-08 00:00:08"); insert into t2 VALUES (7, '2010-01-08 00:00:08');