1
package GenTest::Validator::QueryProperties;
4
@ISA = qw(GenTest::Validator GenTest);
10
use GenTest::Constants;
12
use GenTest::Validator;
15
'RESULTSET_HAS_SAME_DATA_IN_EVERY_ROW',
16
'RESULTSET_IS_SINGLE_INTEGER_ONE',
17
'RESULTSET_HAS_ZERO_OR_ONE_ROWS'
21
foreach my $property (@properties) {
22
$properties{$property} = 1;
26
my ($validator, $executors, $results) = @_;
28
my $query = $results->[0]->query();
29
my @query_properties = $query =~ m{((?:RESULTSET_|ERROR_).*?)[^A-Z_0-9]}sog;
31
return STATUS_WONT_HANDLE if $#query_properties == -1;
33
my $query_status = STATUS_OK;
35
foreach my $result (@$results) {
36
foreach my $query_property (@query_properties) {
37
my $property_status = STATUS_OK;
38
if (exists $properties{$query_property}) {
40
# This is a named property, call the respective validation procedure
42
$property_status = $validator->$query_property($result);
43
} elsif (my ($error) = $query_property =~ m{ERROR_(.*)}so) {
45
# This is an error code, check that the query returned that error code
48
if ($error !~ m{^\d*$}) {
49
say("Query: $query needs to use a numeric code in in query property $query_property.");
50
return STATUS_ENVIRONMENT_FAILURE;
51
} elsif ($result->err() != $error) {
52
say("Query: $query did not fail with error $error.");
53
$property_status = STATUS_ERROR_MISMATCH;
56
$query_status = $property_status if $property_status > $query_status;
60
if ($query_status != STATUS_OK) {
61
say("Query: $query does not have the declared properties.");
62
print Dumper $results if rqg_debug();
69
sub RESULTSET_HAS_SAME_DATA_IN_EVERY_ROW {
70
my ($validator, $result) = @_;
72
return STATUS_OK if not defined $result->data();
73
return STATUS_OK if $result->rows() < 2;
76
foreach my $row (@{$result->data()}) {
77
my $data_item = join('<field>', @{$row});
78
$data_hash{$data_item}++;
81
if (keys(%data_hash) > 1) {
82
return STATUS_CONTENT_MISMATCH;
88
sub RESULTSET_HAS_ZERO_OR_ONE_ROWS {
89
my ($validator, $result) = @_;
91
if ($result->rows() > 1) {
92
return STATUS_LENGTH_MISMATCH;
98
sub RESULTSET_IS_SINGLE_INTEGER_ONE {
99
my ($validator, $result) = @_;
102
(not defined $result->data()) ||
103
($#{$result->data()} != 0) ||
104
($result->rows() != 1) ||
105
($#{$result->data()->[0]} != 0) ||
106
($result->data()->[0]->[0] != 1)
108
return STATUS_CONTENT_MISMATCH;