line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
52
|
use 5.008003; |
|
2
|
|
|
|
|
7
|
|
2
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
58
|
|
3
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
137
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
7
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Scalar::Util qw( blessed ); |
10
|
2
|
|
|
2
|
|
13
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
3082
|
|
11
|
|
|
|
|
|
|
my ( $selection, $name_quoter ) = ( shift, @_ ); |
12
|
|
|
|
|
|
|
|
13
|
6
|
|
|
6
|
0
|
15
|
return unless blessed( $selection ); |
14
|
|
|
|
|
|
|
return unless $selection->isa( 'LINQ::FieldSet::Selection' ); |
15
|
6
|
50
|
|
|
|
22
|
return if $selection->seen_asterisk; |
16
|
6
|
50
|
|
|
|
26
|
|
17
|
6
|
50
|
|
|
|
105
|
$name_quoter ||= sub { |
18
|
|
|
|
|
|
|
my $name = shift; |
19
|
|
|
|
|
|
|
return sprintf( '"%s"', quotemeta( $name ) ); |
20
|
4
|
|
|
4
|
|
7
|
}; |
21
|
4
|
|
|
|
|
19
|
|
22
|
6
|
|
100
|
|
|
160
|
my @cols; |
23
|
|
|
|
|
|
|
for my $field ( @{ $selection->fields } ) { |
24
|
6
|
|
|
|
|
9
|
my $orig_name = $field->value; |
25
|
6
|
|
|
|
|
10
|
my $aliased = $field->name; |
|
6
|
|
|
|
|
100
|
|
26
|
8
|
|
|
|
|
1952
|
return if ref( $orig_name ); |
27
|
8
|
|
|
|
|
148
|
# uncoverable branch true |
28
|
8
|
50
|
|
|
|
44
|
return if !defined( $aliased ); |
29
|
|
|
|
|
|
|
|
30
|
8
|
50
|
|
|
|
21
|
push @cols, $name_quoter->( $orig_name ); |
31
|
|
|
|
|
|
|
} #/ for my $field ( @{ $self...}) |
32
|
8
|
|
|
|
|
18
|
|
33
|
|
|
|
|
|
|
return join( q[, ], @cols ); |
34
|
|
|
|
|
|
|
} #/ sub _sql_selection |
35
|
6
|
|
|
|
|
127
|
|
36
|
|
|
|
|
|
|
my ( $assertion, $name_quoter, $value_quoter ) = ( @_ ); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
return unless blessed( $assertion ); |
39
|
5
|
|
|
5
|
0
|
14
|
|
40
|
|
|
|
|
|
|
$name_quoter ||= sub { |
41
|
5
|
50
|
|
|
|
19
|
my $name = shift; |
42
|
|
|
|
|
|
|
return sprintf( '"%s"', quotemeta( $name ) ); |
43
|
|
|
|
|
|
|
}; |
44
|
2
|
|
|
2
|
|
11
|
|
45
|
2
|
|
|
|
|
12
|
$value_quoter ||= sub { |
46
|
5
|
|
100
|
|
|
29
|
my $name = shift; |
47
|
|
|
|
|
|
|
return sprintf( '"%s"', quotemeta( $name ) ); |
48
|
|
|
|
|
|
|
}; |
49
|
2
|
|
|
2
|
|
11
|
|
50
|
2
|
|
|
|
|
18
|
if ( $assertion->isa( 'LINQ::FieldSet::Assertion::AND' ) ) { |
51
|
5
|
|
100
|
|
|
20
|
return _assertion_to_sql_AND( $assertion, $name_quoter, $value_quoter ); |
52
|
|
|
|
|
|
|
} |
53
|
5
|
50
|
|
|
|
52
|
elsif ( $assertion->isa( 'LINQ::FieldSet::Assertion::OR' ) ) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
return _assertion_to_sql_OR( $assertion, $name_quoter, $value_quoter ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
elsif ( $assertion->isa( 'LINQ::FieldSet::Assertion::NOT' ) ) { |
57
|
0
|
|
|
|
|
0
|
return _assertion_to_sql_NOT( $assertion, $name_quoter, $value_quoter ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
elsif ( $assertion->isa( 'LINQ::FieldSet::Assertion' ) ) { |
60
|
0
|
|
|
|
|
0
|
return _assertion_to_sql_FIELDSET( $assertion, $name_quoter, $value_quoter ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
5
|
|
|
|
|
13
|
|
64
|
|
|
|
|
|
|
my ( $assertion, $name_quoter, $value_quoter ) = ( @_ ); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $left = assertion_to_sql( $assertion->left, $name_quoter, $value_quoter ) |
67
|
|
|
|
|
|
|
or return; |
68
|
0
|
|
|
0
|
|
0
|
my $right = assertion_to_sql( $assertion->right, $name_quoter, $value_quoter ) |
69
|
|
|
|
|
|
|
or return; |
70
|
0
|
0
|
|
|
|
0
|
|
71
|
|
|
|
|
|
|
return "($left) AND ($right)"; |
72
|
0
|
0
|
|
|
|
0
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my ( $assertion, $name_quoter, $value_quoter ) = ( @_ ); |
75
|
0
|
|
|
|
|
0
|
|
76
|
|
|
|
|
|
|
my $left = assertion_to_sql( $assertion->left, $name_quoter, $value_quoter ) |
77
|
|
|
|
|
|
|
or return; |
78
|
|
|
|
|
|
|
my $right = assertion_to_sql( $assertion->right, $name_quoter, $value_quoter ) |
79
|
0
|
|
|
0
|
|
0
|
or return; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
0
|
return "($left) OR ($right)"; |
82
|
|
|
|
|
|
|
} |
83
|
0
|
0
|
|
|
|
0
|
|
84
|
|
|
|
|
|
|
my ( $assertion, $name_quoter, $value_quoter ) = ( @_ ); |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
0
|
my $left = assertion_to_sql( $assertion->left, $name_quoter, $value_quoter ) |
87
|
|
|
|
|
|
|
or return; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
return "NOT ($left)"; |
90
|
0
|
|
|
0
|
|
0
|
} |
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
0
|
my ( $assertion, $name_quoter, $value_quoter ) = ( @_ ); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my @fields; |
95
|
0
|
|
|
|
|
0
|
for my $field ( @{ $assertion->fields } ) { |
96
|
|
|
|
|
|
|
my $field_sql = _assertion_to_sql_FIELD( $field, $name_quoter, $value_quoter ) |
97
|
|
|
|
|
|
|
or return; |
98
|
|
|
|
|
|
|
push @fields, "($field_sql)"; |
99
|
5
|
|
|
5
|
|
11
|
} |
100
|
|
|
|
|
|
|
|
101
|
5
|
|
|
|
|
7
|
join " AND ", @fields; |
102
|
5
|
|
|
|
|
9
|
} |
|
5
|
|
|
|
|
113
|
|
103
|
5
|
100
|
|
|
|
140
|
|
104
|
|
|
|
|
|
|
my ( $field, $name_quoter, $value_quoter ) = ( @_ ); |
105
|
4
|
|
|
|
|
14
|
|
106
|
|
|
|
|
|
|
return if ref( $field->value ); |
107
|
|
|
|
|
|
|
my $result; |
108
|
4
|
|
|
|
|
26
|
|
109
|
|
|
|
|
|
|
if ( exists $field->params->{is} ) { |
110
|
|
|
|
|
|
|
$result = _assertion_to_sql_FIELD_IS( @_ ); |
111
|
|
|
|
|
|
|
} |
112
|
5
|
|
|
5
|
|
11
|
elsif ( exists $field->params->{in} ) { |
113
|
|
|
|
|
|
|
$result = _assertion_to_sql_FIELD_IN( @_ ); |
114
|
5
|
50
|
|
|
|
82
|
} |
115
|
5
|
|
|
|
|
29
|
elsif ( exists $field->params->{like} ) { |
116
|
|
|
|
|
|
|
$result = _assertion_to_sql_FIELD_LIKE( @_ ); |
117
|
5
|
100
|
|
|
|
76
|
} |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
118
|
4
|
|
|
|
|
23
|
elsif ( exists $field->params->{to} ) { |
119
|
|
|
|
|
|
|
$result = _assertion_to_sql_FIELD_TO( @_ ); |
120
|
|
|
|
|
|
|
} |
121
|
0
|
|
|
|
|
0
|
|
122
|
|
|
|
|
|
|
return unless defined $result; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
0
|
if ( exists $field->params->{nix} ) { |
125
|
|
|
|
|
|
|
return "NOT ($result)"; |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
0
|
|
128
|
|
|
|
|
|
|
return $result; |
129
|
|
|
|
|
|
|
} |
130
|
5
|
100
|
|
|
|
86
|
|
131
|
|
|
|
|
|
|
my ( $field, $name_quoter, $value_quoter ) = ( @_ ); |
132
|
4
|
50
|
|
|
|
70
|
|
133
|
0
|
|
|
|
|
0
|
my $cmp = $field->params->{cmp} || '=='; |
134
|
|
|
|
|
|
|
if ( $cmp eq '!=' ) { |
135
|
|
|
|
|
|
|
$cmp = '<>'; # SQL syntax <> Perl syntax |
136
|
4
|
|
|
|
|
29
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my $wrapper = $field->params->{nocase} |
139
|
|
|
|
|
|
|
? sub { sprintf( 'LOWER(%s)', $_[0] ) } |
140
|
4
|
|
|
4
|
|
19
|
: sub { $_[0] }; |
141
|
|
|
|
|
|
|
|
142
|
4
|
|
50
|
|
|
67
|
return sprintf( |
143
|
4
|
50
|
|
|
|
38
|
'%s %s %s', |
144
|
0
|
|
|
|
|
0
|
$wrapper->( $name_quoter->( $field->value ) ), |
145
|
|
|
|
|
|
|
$cmp, |
146
|
|
|
|
|
|
|
$wrapper->( $value_quoter->( $field->params->{is} ) ), |
147
|
|
|
|
|
|
|
); |
148
|
0
|
|
|
0
|
|
0
|
} |
149
|
4
|
50
|
|
8
|
|
63
|
|
|
8
|
|
|
|
|
201
|
|
150
|
|
|
|
|
|
|
my ( $field, $name_quoter, $value_quoter ) = ( @_ ); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
return sprintf( |
153
|
|
|
|
|
|
|
'%s IN (%s)', |
154
|
|
|
|
|
|
|
$name_quoter->( $field->value ), |
155
|
4
|
|
|
|
|
83
|
join( |
156
|
|
|
|
|
|
|
q[, ], |
157
|
|
|
|
|
|
|
map $value_quoter->( $_ ), @{ $field->params->{to} }, |
158
|
|
|
|
|
|
|
), |
159
|
|
|
|
|
|
|
); |
160
|
0
|
|
|
0
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
my ( $field, $name_quoter, $value_quoter ) = ( @_ ); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
my $wrapper = $field->params->{nocase} |
165
|
|
|
|
|
|
|
? sub { sprintf( 'LOWER(%s)', $_[0] ) } |
166
|
|
|
|
|
|
|
: sub { $_[0] }; |
167
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
return sprintf( |
169
|
|
|
|
|
|
|
'%s LIKE %s', |
170
|
|
|
|
|
|
|
$wrapper->( $name_quoter->( $field->value ) ), |
171
|
|
|
|
|
|
|
$wrapper->( $value_quoter->( $field->params->{like} ) ), |
172
|
|
|
|
|
|
|
); |
173
|
0
|
|
|
0
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
my ( $field, $name_quoter, $value_quoter ) = ( @_ ); |
176
|
0
|
|
|
0
|
|
|
|
177
|
0
|
0
|
|
0
|
|
|
my $cmp = $field->params->{cmp} || '=='; |
|
0
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
if ( $cmp eq '!=' ) { |
179
|
|
|
|
|
|
|
$cmp = '<>'; # SQL syntax <> Perl syntax |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
my $wrapper = $field->params->{nocase} |
183
|
|
|
|
|
|
|
? sub { sprintf( 'LOWER(%s)', $_[0] ) } |
184
|
|
|
|
|
|
|
: sub { $_[0] }; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
return sprintf( |
187
|
0
|
|
|
0
|
|
|
'%s %s %s', |
188
|
|
|
|
|
|
|
$wrapper->( $name_quoter->( $field->value ) ), |
189
|
0
|
|
0
|
|
|
|
$cmp, |
190
|
0
|
0
|
|
|
|
|
$wrapper->( $name_quoter->( $field->params->{to} ) ), |
191
|
0
|
|
|
|
|
|
); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
1; |