line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# the contents of this file are Copyright (c) 2009 Daniel Norman |
2
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
3
|
|
|
|
|
|
|
# modify it under the terms of the GNU General Public License as |
4
|
|
|
|
|
|
|
# published by the Free Software Foundation. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
########################################### |
7
|
|
|
|
|
|
|
package DBR::Query::Part::AndOr; |
8
|
|
|
|
|
|
|
|
9
|
18
|
|
|
18
|
|
99
|
use strict; |
|
18
|
|
|
|
|
38
|
|
|
18
|
|
|
|
|
1572
|
|
10
|
18
|
|
|
18
|
|
97
|
use base 'DBR::Query::Part'; |
|
18
|
|
|
|
|
34
|
|
|
18
|
|
|
|
|
1751
|
|
11
|
18
|
|
|
18
|
|
160
|
use Carp; |
|
18
|
|
|
|
|
29
|
|
|
18
|
|
|
|
|
1087
|
|
12
|
18
|
|
|
18
|
|
60056
|
use Data::Dumper; |
|
18
|
|
|
|
|
390609
|
|
|
18
|
|
|
|
|
12427
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new{ |
15
|
268
|
|
|
268
|
0
|
719
|
my( $package ) = shift; |
16
|
|
|
|
|
|
|
|
17
|
268
|
|
|
|
|
850
|
for (@_){ |
18
|
487
|
50
|
|
|
|
3336
|
ref($_) =~ /^DBR::Query::Part::/ || confess("arguments must be part objects ($_)") |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
268
|
|
|
|
|
932
|
my $self = [@_]; |
22
|
|
|
|
|
|
|
|
23
|
268
|
|
|
|
|
1281
|
bless( $self, $package ); |
24
|
|
|
|
|
|
|
|
25
|
268
|
|
|
|
|
1518
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
733
|
|
|
733
|
0
|
1224
|
sub children{ @{$_[0]} } |
|
733
|
|
|
|
|
3610
|
|
29
|
|
|
|
|
|
|
|
30
|
231
|
50
|
|
231
|
|
1305
|
sub _validate_self{ return scalar($_[0]->children)?1:$_[0]->_error('Invalid object') } # AND/OR are only valid if they have at least one child |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub sql { # Used by AND/OR |
33
|
268
|
|
|
268
|
0
|
11870
|
my $self = shift; |
34
|
268
|
50
|
|
|
|
1400
|
my $conn = shift or return $self->_error('conn must be specified'); |
35
|
268
|
|
|
|
|
452
|
my $nested = shift; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
268
|
|
|
|
|
1586
|
my $type = $self->type; |
39
|
268
|
50
|
|
|
|
2234
|
$type =~ /^(AND|OR)$/ or return $self->_error('this sql function is only used for AND/OR'); |
40
|
|
|
|
|
|
|
|
41
|
268
|
|
|
|
|
736
|
my $sql; |
42
|
268
|
100
|
|
|
|
736
|
$sql .= '(' if $nested; |
43
|
268
|
|
|
|
|
1360
|
$sql .= join(' ' . $type . ' ', map { $_->sql($conn,1) } $self->children ); |
|
487
|
|
|
|
|
1991
|
|
44
|
268
|
100
|
|
|
|
894
|
$sql .= ')' if $nested; |
45
|
|
|
|
|
|
|
|
46
|
268
|
|
|
|
|
1107
|
return $sql; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
########################################### |
52
|
|
|
|
|
|
|
package DBR::Query::Part::And; |
53
|
18
|
|
|
18
|
|
200
|
use strict; |
|
18
|
|
|
|
|
35
|
|
|
18
|
|
|
|
|
3599
|
|
54
|
|
|
|
|
|
|
our @ISA = ('DBR::Query::Part::AndOr'); |
55
|
|
|
|
|
|
|
|
56
|
257
|
|
|
257
|
|
11486
|
sub type { return 'AND' }; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#If any children are empty, we are empty |
59
|
|
|
|
|
|
|
sub is_emptyset{ |
60
|
3
|
|
50
|
3
|
|
22
|
$_->is_emptyset && return 1 for ($_[0]->children); |
61
|
3
|
|
|
|
|
16
|
return 0; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
########################################### |
67
|
|
|
|
|
|
|
package DBR::Query::Part::Or; |
68
|
18
|
|
|
18
|
|
103
|
use strict; |
|
18
|
|
|
|
|
41
|
|
|
18
|
|
|
|
|
3680
|
|
69
|
|
|
|
|
|
|
our @ISA = ('DBR::Query::Part::AndOr'); |
70
|
|
|
|
|
|
|
|
71
|
11
|
|
|
11
|
|
25
|
sub type { return 'OR' }; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# If any children are non-empty, then we are non-empty |
74
|
|
|
|
|
|
|
sub is_emptyset{ |
75
|
0
|
|
0
|
0
|
|
|
$_->is_emptyset || return 0 for ($_[0]->children); |
76
|
0
|
|
|
|
|
|
return 1; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |