1
# Copyright (C) 2008-2009 Sun Microsystems, Inc. All rights reserved.
2
# Use is subject to license terms.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18
package GenTest::Validator::QueryProperties;
21
@ISA = qw(GenTest::Validator GenTest);
27
use GenTest::Constants;
29
use GenTest::Validator;
32
'RESULTSET_HAS_SAME_DATA_IN_EVERY_ROW',
33
'RESULTSET_IS_SINGLE_INTEGER_ONE',
34
'RESULTSET_HAS_ZERO_OR_ONE_ROWS',
35
'RESULTSET_HAS_ONE_ROW',
36
'QUERY_IS_REPLICATION_SAFE'
40
foreach my $property (@properties) {
41
$properties{$property} = 1;
45
my ($validator, $executors, $results) = @_;
47
my $query = $results->[0]->query();
48
my @query_properties = $query =~ m{((?:RESULTSET_|ERROR_|QUERY_).*?)[^A-Z_0-9]}sog;
50
return STATUS_WONT_HANDLE if $#query_properties == -1;
52
my $query_status = STATUS_OK;
54
foreach my $result (@$results) {
55
foreach my $query_property (@query_properties) {
56
my $property_status = STATUS_OK;
57
if (exists $properties{$query_property}) {
59
# This is a named property, call the respective validation procedure
61
$property_status = $validator->$query_property($result);
62
} elsif (my ($error) = $query_property =~ m{ERROR_(.*)}so) {
64
# This is an error code, check that the query returned that error code
67
if ($error !~ m{^\d*$}) {
68
say("Query: $query needs to use a numeric code in in query property $query_property.");
69
return STATUS_ENVIRONMENT_FAILURE;
70
} elsif ($result->err() != $error) {
71
say("Query: $query did not fail with error $error.");
72
$property_status = STATUS_ERROR_MISMATCH;
75
$query_status = $property_status if $property_status > $query_status;
79
if ($query_status != STATUS_OK) {
80
say("Query: $query does not have the declared properties: ".join(', ', @query_properties));
81
print Dumper $results if rqg_debug();
88
sub RESULTSET_HAS_SAME_DATA_IN_EVERY_ROW {
89
my ($validator, $result) = @_;
91
return STATUS_OK if not defined $result->data();
92
return STATUS_OK if $result->rows() < 2;
95
foreach my $row (@{$result->data()}) {
96
my $data_item = join('<field>', @{$row});
97
$data_hash{$data_item}++;
100
if (keys(%data_hash) > 1) {
101
return STATUS_CONTENT_MISMATCH;
107
sub RESULTSET_HAS_ZERO_OR_ONE_ROWS {
108
my ($validator, $result) = @_;
110
if ($result->rows() > 1) {
111
return STATUS_LENGTH_MISMATCH;
117
sub RESULTSET_HAS_ONE_ROW {
118
my ($validator, $result) = @_;
120
if ($result->rows() != 1) {
121
return STATUS_LENGTH_MISMATCH;
127
sub RESULTSET_IS_SINGLE_INTEGER_ONE {
128
my ($validator, $result) = @_;
131
(not defined $result->data()) ||
132
($#{$result->data()} != 0) ||
133
($result->rows() != 1) ||
134
($#{$result->data()->[0]} != 0) ||
135
($result->data()->[0]->[0] != 1)
137
return STATUS_CONTENT_MISMATCH;
143
sub QUERY_IS_REPLICATION_SAFE {
145
my ($validator, $result) = @_;
147
my $warnings = $result->warnings();
149
if (defined $warnings) {
150
foreach my $warning (@$warnings) {
151
return STATUS_ENVIRONMENT_FAILURE if $warning->[1] == 1592;