mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-20 02:44:58 +00:00
Rename results file results to rows and meta to results. Test more --save-results.
This commit is contained in:
@@ -5932,13 +5932,13 @@ has '_query_fh' => (
|
||||
required => 0,
|
||||
);
|
||||
|
||||
has '_meta_fh' => (
|
||||
has '_results_fh' => (
|
||||
is => 'rw',
|
||||
isa => 'Maybe[FileHandle]',
|
||||
required => 0,
|
||||
);
|
||||
|
||||
has '_results_fh' => (
|
||||
has '_rows_fh' => (
|
||||
is => 'rw',
|
||||
isa => 'Maybe[FileHandle]',
|
||||
required => 0,
|
||||
@@ -5954,19 +5954,19 @@ sub BUILDARGS {
|
||||
open my $_query_fh, '>', $query_file
|
||||
or die "Cannot open $query_file for writing: $OS_ERROR";
|
||||
|
||||
my $meta_file = "$dir/meta";
|
||||
open my $_meta_fh, '>', $meta_file
|
||||
or die "Cannot open $meta_file for writing: $OS_ERROR";
|
||||
|
||||
my $results_file = "$dir/results";
|
||||
open my $_results_fh, '>', $results_file
|
||||
or die "Cannot open $results_file for writing: $OS_ERROR";
|
||||
|
||||
my $rows_file = "$dir/rows";
|
||||
open my $_rows_fh, '>', $rows_file
|
||||
or die "Cannot open $rows_file for writing: $OS_ERROR";
|
||||
|
||||
my $self = {
|
||||
%$args,
|
||||
_query_fh => $_query_fh,
|
||||
_meta_fh => $_meta_fh,
|
||||
_results_fh => $_results_fh,
|
||||
_rows_fh => $_rows_fh,
|
||||
};
|
||||
|
||||
return $self;
|
||||
@@ -5982,18 +5982,30 @@ sub save {
|
||||
print { $self->_query_fh } $event->{arg}, "\n##\n";
|
||||
|
||||
if ( my $error = $results->{error} ) {
|
||||
print { $self->_meta_fh } $error, "\n##\n";
|
||||
print { $self->_results_fh } '', "\n##\n";
|
||||
print { $self->_results_fh }
|
||||
$self->dumper({ error => $error}, 'results'), "\n##\n";
|
||||
|
||||
print { $self->_rows_fh } "\n##\n";
|
||||
}
|
||||
else {
|
||||
my $sth = $results->{sth};
|
||||
my $rows = $sth->fetchall_arrayref();
|
||||
my $rows;
|
||||
if ( my $sth = $results->{sth} ) {
|
||||
if ( $event->{arg} =~ m/(?:^\s*SELECT|(?:\*\/\s*SELECT))/i ) {
|
||||
$rows = $sth->fetchall_arrayref();
|
||||
}
|
||||
eval {
|
||||
$sth->finish;
|
||||
delete $results->{sth};
|
||||
};
|
||||
print { $self->_meta_fh } $self->dumper($results, 'meta'), "\n##\n";
|
||||
print { $self->_results_fh } $self->dumper($rows, 'results'), "\n##\n";
|
||||
if ( $EVAL_ERROR ) {
|
||||
PTDEBUG && _d($EVAL_ERROR);
|
||||
}
|
||||
}
|
||||
print { $self->_rows_fh }
|
||||
($rows ? $self->dumper($rows, 'rows') : ''), "\n##\n";
|
||||
|
||||
delete $results->{error};
|
||||
delete $results->{sth};
|
||||
print { $self->_results_fh } $self->dumper($results, 'results'), "\n##\n";
|
||||
}
|
||||
|
||||
return;
|
||||
|
@@ -48,13 +48,13 @@ has '_query_fh' => (
|
||||
required => 0,
|
||||
);
|
||||
|
||||
has '_meta_fh' => (
|
||||
has '_results_fh' => (
|
||||
is => 'rw',
|
||||
isa => 'Maybe[FileHandle]',
|
||||
required => 0,
|
||||
);
|
||||
|
||||
has '_results_fh' => (
|
||||
has '_rows_fh' => (
|
||||
is => 'rw',
|
||||
isa => 'Maybe[FileHandle]',
|
||||
required => 0,
|
||||
@@ -70,19 +70,19 @@ sub BUILDARGS {
|
||||
open my $_query_fh, '>', $query_file
|
||||
or die "Cannot open $query_file for writing: $OS_ERROR";
|
||||
|
||||
my $meta_file = "$dir/meta";
|
||||
open my $_meta_fh, '>', $meta_file
|
||||
or die "Cannot open $meta_file for writing: $OS_ERROR";
|
||||
|
||||
my $results_file = "$dir/results";
|
||||
open my $_results_fh, '>', $results_file
|
||||
or die "Cannot open $results_file for writing: $OS_ERROR";
|
||||
|
||||
my $rows_file = "$dir/rows";
|
||||
open my $_rows_fh, '>', $rows_file
|
||||
or die "Cannot open $rows_file for writing: $OS_ERROR";
|
||||
|
||||
my $self = {
|
||||
%$args,
|
||||
_query_fh => $_query_fh,
|
||||
_meta_fh => $_meta_fh,
|
||||
_results_fh => $_results_fh,
|
||||
_rows_fh => $_rows_fh,
|
||||
};
|
||||
|
||||
return $self;
|
||||
@@ -95,21 +95,38 @@ sub save {
|
||||
my $event = $args{event};
|
||||
my $results = $args{results};
|
||||
|
||||
# Save the query.
|
||||
print { $self->_query_fh } $event->{arg}, "\n##\n";
|
||||
|
||||
if ( my $error = $results->{error} ) {
|
||||
print { $self->_meta_fh } $error, "\n##\n";
|
||||
print { $self->_results_fh } '', "\n##\n";
|
||||
# Save the error.
|
||||
print { $self->_results_fh }
|
||||
$self->dumper({ error => $error}, 'results'), "\n##\n";
|
||||
|
||||
# Save empty rows.
|
||||
print { $self->_rows_fh } "\n##\n";
|
||||
}
|
||||
else {
|
||||
my $sth = $results->{sth};
|
||||
my $rows = $sth->fetchall_arrayref();
|
||||
# Save rows, if any (i.e. if it's a SELECT statement).
|
||||
my $rows;
|
||||
if ( my $sth = $results->{sth} ) {
|
||||
if ( $event->{arg} =~ m/(?:^\s*SELECT|(?:\*\/\s*SELECT))/i ) {
|
||||
$rows = $sth->fetchall_arrayref();
|
||||
}
|
||||
eval {
|
||||
$sth->finish;
|
||||
delete $results->{sth};
|
||||
};
|
||||
print { $self->_meta_fh } $self->dumper($results, 'meta'), "\n##\n";
|
||||
print { $self->_results_fh } $self->dumper($rows, 'results'), "\n##\n";
|
||||
if ( $EVAL_ERROR ) {
|
||||
PTDEBUG && _d($EVAL_ERROR);
|
||||
}
|
||||
}
|
||||
print { $self->_rows_fh }
|
||||
($rows ? $self->dumper($rows, 'rows') : ''), "\n##\n";
|
||||
|
||||
# Save results.
|
||||
delete $results->{error};
|
||||
delete $results->{sth};
|
||||
print { $self->_results_fh } $self->dumper($results, 'results'), "\n##\n";
|
||||
}
|
||||
|
||||
return;
|
||||
|
@@ -1,34 +1,6 @@
|
||||
$results = [
|
||||
[
|
||||
'1',
|
||||
'a',
|
||||
'2013-01-01 00:00:01'
|
||||
],
|
||||
[
|
||||
'2',
|
||||
'b',
|
||||
'2013-01-01 00:00:02'
|
||||
],
|
||||
[
|
||||
'3',
|
||||
'c',
|
||||
'2013-01-01 00:00:03'
|
||||
],
|
||||
[
|
||||
'4',
|
||||
'd',
|
||||
'2013-01-01 00:00:04'
|
||||
],
|
||||
[
|
||||
'5',
|
||||
'e',
|
||||
'2013-01-01 00:00:05'
|
||||
],
|
||||
[
|
||||
'6',
|
||||
'f',
|
||||
'2013-01-01 00:00:06'
|
||||
]
|
||||
];
|
||||
$results = {
|
||||
query_time => '0',
|
||||
warnings => {}
|
||||
};
|
||||
|
||||
##
|
||||
|
34
t/pt-upgrade/samples/001/select_results/rows
Normal file
34
t/pt-upgrade/samples/001/select_results/rows
Normal file
@@ -0,0 +1,34 @@
|
||||
$rows = [
|
||||
[
|
||||
'1',
|
||||
'a',
|
||||
'2013-01-01 00:00:01'
|
||||
],
|
||||
[
|
||||
'2',
|
||||
'b',
|
||||
'2013-01-01 00:00:02'
|
||||
],
|
||||
[
|
||||
'3',
|
||||
'c',
|
||||
'2013-01-01 00:00:03'
|
||||
],
|
||||
[
|
||||
'4',
|
||||
'd',
|
||||
'2013-01-01 00:00:04'
|
||||
],
|
||||
[
|
||||
'5',
|
||||
'e',
|
||||
'2013-01-01 00:00:05'
|
||||
],
|
||||
[
|
||||
'6',
|
||||
'f',
|
||||
'2013-01-01 00:00:06'
|
||||
]
|
||||
];
|
||||
|
||||
##
|
@@ -0,0 +1,2 @@
|
||||
select * from test.t order by id
|
||||
##
|
@@ -1,5 +1,4 @@
|
||||
$meta = {
|
||||
error => undef,
|
||||
$results = {
|
||||
query_time => '0',
|
||||
warnings => {}
|
||||
};
|
34
t/pt-upgrade/samples/002/select_missing_rows_results/rows
Normal file
34
t/pt-upgrade/samples/002/select_missing_rows_results/rows
Normal file
@@ -0,0 +1,34 @@
|
||||
$rows = [
|
||||
[
|
||||
'1',
|
||||
'a',
|
||||
'2013-01-01 00:00:01'
|
||||
],
|
||||
[
|
||||
'2',
|
||||
'b',
|
||||
'2013-01-01 00:00:02'
|
||||
],
|
||||
[
|
||||
'3',
|
||||
'c',
|
||||
'2013-01-01 00:00:03'
|
||||
],
|
||||
[
|
||||
'4',
|
||||
'd',
|
||||
'2013-01-01 00:00:04'
|
||||
],
|
||||
[
|
||||
'5',
|
||||
'e',
|
||||
'2013-01-01 00:00:05'
|
||||
],
|
||||
[
|
||||
'6',
|
||||
'f',
|
||||
'2013-01-01 00:00:06'
|
||||
]
|
||||
];
|
||||
|
||||
##
|
@@ -0,0 +1,2 @@
|
||||
INSERT INTO t (id, username) VALUES (NULL, 'long_username')
|
||||
##
|
@@ -0,0 +1,12 @@
|
||||
$results = {
|
||||
query_time => '0',
|
||||
warnings => {
|
||||
'1265' => {
|
||||
code => '1265',
|
||||
level => 'Warning',
|
||||
message => 'Data truncated for column \'username\' at row 1'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
##
|
@@ -0,0 +1,2 @@
|
||||
|
||||
##
|
@@ -0,0 +1,2 @@
|
||||
select nonexistent_col from test.t
|
||||
##
|
@@ -0,0 +1,5 @@
|
||||
$results = {
|
||||
error => 'DBD::mysql::st execute failed: Unknown column \'nonexistent_col\' in \'field list\' [for Statement "select nonexistent_col from test.t"]'
|
||||
};
|
||||
|
||||
##
|
@@ -0,0 +1,2 @@
|
||||
|
||||
##
|
2
t/pt-upgrade/samples/005/error_on_host1_results/query
Normal file
2
t/pt-upgrade/samples/005/error_on_host1_results/query
Normal file
@@ -0,0 +1,2 @@
|
||||
select host2_col from test.t
|
||||
##
|
5
t/pt-upgrade/samples/005/error_on_host1_results/results
Normal file
5
t/pt-upgrade/samples/005/error_on_host1_results/results
Normal file
@@ -0,0 +1,5 @@
|
||||
$results = {
|
||||
error => 'DBD::mysql::st execute failed: Unknown column \'host2_col\' in \'field list\' [for Statement "select host2_col from test.t"]'
|
||||
};
|
||||
|
||||
##
|
2
t/pt-upgrade/samples/005/error_on_host1_results/rows
Normal file
2
t/pt-upgrade/samples/005/error_on_host1_results/rows
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
##
|
2
t/pt-upgrade/samples/005/error_on_host2_results/query
Normal file
2
t/pt-upgrade/samples/005/error_on_host2_results/query
Normal file
@@ -0,0 +1,2 @@
|
||||
select host1_col from test.t
|
||||
##
|
6
t/pt-upgrade/samples/005/error_on_host2_results/results
Normal file
6
t/pt-upgrade/samples/005/error_on_host2_results/results
Normal file
@@ -0,0 +1,6 @@
|
||||
$results = {
|
||||
query_time => '0',
|
||||
warnings => {}
|
||||
};
|
||||
|
||||
##
|
7
t/pt-upgrade/samples/005/error_on_host2_results/rows
Normal file
7
t/pt-upgrade/samples/005/error_on_host2_results/rows
Normal file
@@ -0,0 +1,7 @@
|
||||
$rows = [
|
||||
[
|
||||
'1'
|
||||
]
|
||||
];
|
||||
|
||||
##
|
Reference in New Issue
Block a user