From 9ae940cd7661abb95375f9ddd01efc8c224fd84f Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Wed, 11 Jul 2012 17:29:04 -0300 Subject: [PATCH] PerconaTest: Add load_data_is_disabled and correct full_output load_data_is_disabled checks if LOAD DATA LOCAL INFILE is disabled; it'll be used in the future by a couple of tests. full_output was changed to use two different filehandles for STDOUT and STDERR; THis is because otherwise, code closing STDOUT (like the --quiet option in pt-osc) would also accidentally close STDERR. --- lib/PerconaTest.pm | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/PerconaTest.pm b/lib/PerconaTest.pm index 08fbd0f2..8221de9b 100644 --- a/lib/PerconaTest.pm +++ b/lib/PerconaTest.pm @@ -717,12 +717,17 @@ sub full_output { my ( $code, %args ) = @_; die "I need a code argument" unless $code; - my (undef, $file) = tempfile(); - open *output_fh, '>', $file - or die "Cannot open file $file: $OS_ERROR"; - local *STDOUT = *output_fh; + local (*STDOUT, *STDERR); + require IO::File; - *STDERR = *STDOUT; + my (undef, $file) = tempfile(); + open *STDOUT, '>', $file + or die "Cannot open file $file: $OS_ERROR"; + *STDOUT->autoflush(1); + + open *STDERR, '>', $file + or die "Cannot open file $file: $OS_ERROR"; + *STDERR->autoflush(1); my $status; if (my $pid = fork) { @@ -745,7 +750,7 @@ sub full_output { else { exit $code->(); } - close *output_fh; + close $_ or die "Cannot close $_: $OS_ERROR" for qw(STDOUT STDERR); my $output = do { local $/; open my $fh, "<", $file or die $!; <$fh> }; return ($output, $status); @@ -772,6 +777,19 @@ sub tables_used { return [ sort keys %tables ]; } +sub load_data_is_disabled { + my ($dbh) = @_; + my $sql = "LOAD DATA LOCAL INFILE '/dev/null' INTO TABLE " + . "`t`.`pt_not_there`"; + local $@; + if (!eval { $dbh->do($sql); 1 } ) { + my $e = $@; + return 1 if $e =~ qr/\QDBD::mysql::db do failed: The used command is not allowed with this MySQL version [for Statement "LOAD DATA LOCAL INFILE/; + } + + return; +} + 1; } # ###########################################################################