line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SQL::Statement::Term; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
###################################################################### |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# This module is copyright (c), 2009-2020 by Jens Rehsack. |
6
|
|
|
|
|
|
|
# All rights reserved. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# It may be freely distributed under the same terms as Perl itself. |
9
|
|
|
|
|
|
|
# See below for help and copyright information (search for SYNOPSIS). |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
###################################################################### |
12
|
|
|
|
|
|
|
|
13
|
16
|
|
|
16
|
|
114
|
use strict; |
|
16
|
|
|
|
|
34
|
|
|
16
|
|
|
|
|
517
|
|
14
|
16
|
|
|
16
|
|
90
|
use warnings FATAL => "all"; |
|
16
|
|
|
|
|
34
|
|
|
16
|
|
|
|
|
773
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '1.413_001'; |
17
|
|
|
|
|
|
|
|
18
|
16
|
|
|
16
|
|
95
|
use Scalar::Util qw(weaken); |
|
16
|
|
|
|
|
33
|
|
|
16
|
|
|
|
|
782
|
|
19
|
16
|
|
|
16
|
|
93
|
use Carp (); |
|
16
|
|
|
|
|
30
|
|
|
16
|
|
|
|
|
2880
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=pod |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 NAME |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
SQL::Statement::Term - base class for all terms |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 SYNOPSIS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# create a term with an SQL::Statement object as owner |
30
|
|
|
|
|
|
|
my $term = SQL::Statement::Term->new( $owner ); |
31
|
|
|
|
|
|
|
# access the value of that term |
32
|
|
|
|
|
|
|
$term->value( $eval ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 DESCRIPTION |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
SQL::Statement::Term is an abstract base class providing the interface |
37
|
|
|
|
|
|
|
for all terms. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 INHERITANCE |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
SQL::Statement::Term |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 METHODS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 new |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Instantiates new term and stores a weak reference to the owner. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 value |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
I method which will return the value of the term. Must be |
52
|
|
|
|
|
|
|
overridden by derived classes. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 DESTROY |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Destroys the term and undefines the weak reference to the owner. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub new |
61
|
|
|
|
|
|
|
{ |
62
|
2926
|
|
|
2926
|
1
|
4409
|
my $class = $_[0]; |
63
|
2926
|
|
|
|
|
3875
|
my $owner = $_[1]; |
64
|
|
|
|
|
|
|
|
65
|
2926
|
|
|
|
|
6651
|
my $self = bless( { OWNER => $owner }, $class ); |
66
|
2926
|
|
|
|
|
8406
|
weaken( $self->{OWNER} ); |
67
|
|
|
|
|
|
|
|
68
|
2926
|
|
|
|
|
5342
|
return $self; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub DESTROY |
72
|
|
|
|
|
|
|
{ |
73
|
2925
|
|
|
2925
|
|
4496
|
my $self = $_[0]; |
74
|
2925
|
|
|
|
|
10016
|
undef $self->{OWNER}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub value($) |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
0
|
0
|
1
|
0
|
Carp::confess( sprintf( q{pure virtual function '%s->value' called}, ref( $_[0] ) || __PACKAGE__ ) ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
package SQL::Statement::ConstantTerm; |
83
|
|
|
|
|
|
|
|
84
|
16
|
|
|
16
|
|
122
|
use vars qw(@ISA); |
|
16
|
|
|
|
|
32
|
|
|
16
|
|
|
|
|
2668
|
|
85
|
|
|
|
|
|
|
@ISA = qw(SQL::Statement::Term); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=pod |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 NAME |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
SQL::Statement::ConstantTerm - term for constant values |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SYNOPSIS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# create a term with an SQL::Statement object as owner |
96
|
|
|
|
|
|
|
my $term = SQL::Statement::ConstantTerm->new( $owner, 'foo' ); |
97
|
|
|
|
|
|
|
# access the value of that term - returns 'foo' |
98
|
|
|
|
|
|
|
$term->value( $eval ); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 DESCRIPTION |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
SQL::Statement::ConstantTerm implements a term which will always return the |
103
|
|
|
|
|
|
|
same constant value. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 INHERITANCE |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
SQL::Statement::ConstantTerm |
108
|
|
|
|
|
|
|
ISA SQL::Statement::Term |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 METHODS |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 new |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Instantiates new term and stores the constant to deliver and a weak |
115
|
|
|
|
|
|
|
reference to the owner. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 value |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Returns the specified constant. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub new |
124
|
|
|
|
|
|
|
{ |
125
|
1173
|
|
|
1173
|
|
2410
|
my ( $class, $owner, $value ) = @_; |
126
|
|
|
|
|
|
|
|
127
|
1173
|
|
|
|
|
2440
|
my $self = $class->SUPER::new($owner); |
128
|
1173
|
|
|
|
|
2343
|
$self->{VALUE} = $value; |
129
|
|
|
|
|
|
|
|
130
|
1173
|
|
|
|
|
2584
|
return $self; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
1765
|
|
|
1765
|
|
4450
|
sub value($$) { return $_[0]->{VALUE}; } |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
package SQL::Statement::ColumnValue; |
136
|
|
|
|
|
|
|
|
137
|
16
|
|
|
16
|
|
149
|
use vars qw(@ISA); |
|
16
|
|
|
|
|
38
|
|
|
16
|
|
|
|
|
779
|
|
138
|
|
|
|
|
|
|
@ISA = qw(SQL::Statement::Term); |
139
|
|
|
|
|
|
|
|
140
|
16
|
|
|
16
|
|
98
|
use Carp qw(croak); |
|
16
|
|
|
|
|
32
|
|
|
16
|
|
|
|
|
807
|
|
141
|
16
|
|
|
16
|
|
102
|
use Params::Util qw(_INSTANCE _ARRAY0 _SCALAR); |
|
16
|
|
|
|
|
42
|
|
|
16
|
|
|
|
|
928
|
|
142
|
16
|
|
|
16
|
|
101
|
use Scalar::Util qw(looks_like_number); |
|
16
|
|
|
|
|
63
|
|
|
16
|
|
|
|
|
7866
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=pod |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 NAME |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
SQL::Statement::ColumnValue - term for column values |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 SYNOPSIS |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# create a term with an SQL::Statement object as owner |
153
|
|
|
|
|
|
|
my $term = SQL::Statement::ColumnValue->new( $owner, 'id' ); |
154
|
|
|
|
|
|
|
# access the value of that term - returns the value of the column 'id' |
155
|
|
|
|
|
|
|
# of the currently active row in $eval |
156
|
|
|
|
|
|
|
$term->value( $eval ); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 DESCRIPTION |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
SQL::Statement::ColumnValue implements a term which will return the specified |
161
|
|
|
|
|
|
|
column of the active row. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 INHERITANCE |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
SQL::Statement::ColumnValue |
166
|
|
|
|
|
|
|
ISA SQL::Statement::Term |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 METHODS |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 new |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Instantiates new term and stores the column name to deliver and a weak |
173
|
|
|
|
|
|
|
reference to the owner. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 value |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Returns the specified column value. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub new |
182
|
|
|
|
|
|
|
{ |
183
|
1096
|
|
|
1096
|
|
2221
|
my ( $class, $owner, $value ) = @_; |
184
|
|
|
|
|
|
|
|
185
|
1096
|
|
|
|
|
2420
|
my $self = $class->SUPER::new($owner); |
186
|
1096
|
|
|
|
|
2083
|
$self->{VALUE} = $value; |
187
|
|
|
|
|
|
|
|
188
|
1096
|
|
|
|
|
2886
|
return $self; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub value($) |
192
|
|
|
|
|
|
|
{ |
193
|
18140
|
|
|
18140
|
|
28079
|
my ( $self, $eval ) = @_; |
194
|
18140
|
100
|
|
|
|
32578
|
unless ( defined( $self->{TMPVAL} ) ) |
195
|
|
|
|
|
|
|
{ |
196
|
336
|
|
|
|
|
926
|
my ( $tbl, $col ) = $self->{OWNER}->full_qualified_column_name( $self->{VALUE} ); |
197
|
336
|
50
|
|
|
|
779
|
defined($tbl) or croak("Can't find table containing column named '$self->{VALUE}'"); |
198
|
336
|
50
|
|
|
|
652
|
defined($col) or croak("Unknown column: '$self->{VALUE}'"); |
199
|
336
|
|
|
|
|
966
|
$self->{TMPVAL} = $tbl . $self->{OWNER}->{dlm} . $col; |
200
|
336
|
|
|
|
|
603
|
$self->{TABLE_NAME} = $tbl; |
201
|
336
|
|
|
|
|
617
|
$self->{COLUMN_NAME} = $col; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# XXX - can TMPVAL being defined without TABLE_NAME? |
205
|
18140
|
50
|
|
|
|
31278
|
unless ( defined( $self->{TABLE_NAME} ) ) |
206
|
|
|
|
|
|
|
{ |
207
|
0
|
|
|
|
|
0
|
croak( "No table specified: '" . $self->{OWNER}->{original_string} . "'" ); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
# with TempEval: return $eval->column($self->{TABLE_NAME}, $self->{COLUMN_NAME}); |
211
|
18140
|
|
|
|
|
22239
|
my $fp; |
212
|
|
|
|
|
|
|
defined( $fp = $self->{fastpath}->{ "${eval}." . $self->{TABLE_NAME} } ) |
213
|
18140
|
100
|
|
|
|
60619
|
and return &$fp( $self->{COLUMN_NAME} ); |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
defined( $fp = $self->{fastpath}->{ "${eval}." . $self->{TMPVAL} } ) |
216
|
1413
|
100
|
|
|
|
4444
|
and return &$fp( $self->{TMPVAL} ); |
217
|
|
|
|
|
|
|
|
218
|
394
|
100
|
|
|
|
2734
|
if ( defined( _INSTANCE( $eval, 'SQL::Eval' ) ) ) |
|
|
50
|
|
|
|
|
|
219
|
|
|
|
|
|
|
{ |
220
|
|
|
|
|
|
|
$self->{fastpath}->{ "${eval}." . $self->{TABLE_NAME} } = |
221
|
224
|
|
|
|
|
721
|
$eval->_gen_access_fastpath( $self->{TABLE_NAME} ); |
222
|
224
|
|
|
|
|
491
|
return &{ $self->{fastpath}->{ "${eval}." . $self->{TABLE_NAME} } }( $self->{COLUMN_NAME} ); |
|
224
|
|
|
|
|
803
|
|
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
elsif ( defined( _INSTANCE( $eval, 'SQL::Eval::Table' ) ) ) |
225
|
|
|
|
|
|
|
{ |
226
|
|
|
|
|
|
|
$self->{fastpath}->{ "${eval}." . $self->{TMPVAL} } = |
227
|
170
|
|
|
|
|
527
|
$eval->_gen_access_fastpath( $self->{TMPVAL} ); |
228
|
170
|
|
|
|
|
344
|
return &{ $self->{fastpath}->{ "${eval}." . $self->{TMPVAL} } }( $self->{TMPVAL} ); |
|
170
|
|
|
|
|
554
|
|
229
|
|
|
|
|
|
|
# return $eval->column( $self->{TMPVAL} ); |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
else |
232
|
|
|
|
|
|
|
{ |
233
|
0
|
|
|
|
|
|
croak( "Unsupported table storage: '" . ref($eval) . "'" ); |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head1 AUTHOR AND COPYRIGHT |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Copyright (c) 2009-2020 by Jens Rehsack: rehsackATcpan.org |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
All rights reserved. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
You may distribute this module under the terms of either the GNU |
244
|
|
|
|
|
|
|
General Public License or the Artistic License, as specified in |
245
|
|
|
|
|
|
|
the Perl README file. |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=cut |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
1; |