| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package SQL::Entity::Column; |
|
2
|
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
131338
|
use strict; |
|
|
8
|
|
|
|
|
17
|
|
|
|
8
|
|
|
|
|
319
|
|
|
4
|
8
|
|
|
8
|
|
41
|
use warnings; |
|
|
8
|
|
|
|
|
14
|
|
|
|
8
|
|
|
|
|
377
|
|
|
5
|
8
|
|
|
8
|
|
42
|
use vars qw(@EXPORT_OK %EXPORT_TAGS $VERSION); |
|
|
8
|
|
|
|
|
15
|
|
|
|
8
|
|
|
|
|
824
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$VERSION = '0.02'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
6868
|
use Abstract::Meta::Class ':all'; |
|
|
8
|
|
|
|
|
66173
|
|
|
|
8
|
|
|
|
|
1980
|
|
|
10
|
8
|
|
|
8
|
|
73
|
use base 'Exporter'; |
|
|
8
|
|
|
|
|
15
|
|
|
|
8
|
|
|
|
|
6418
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@EXPORT_OK = qw(sql_column); |
|
13
|
|
|
|
|
|
|
%EXPORT_TAGS = (all => \@EXPORT_OK); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
SQL::Entity::Column - Entity column abstraction. |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use SQL::Entity::Column ':all'; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $column = SQL::Entity::Column->new(name => 'name'); |
|
24
|
|
|
|
|
|
|
or |
|
25
|
|
|
|
|
|
|
my $column = sql_column(name => 'name'); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Represents entities column, that maps to the table column, or sql expression. |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 EXPORT |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
None by default. |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sql_column by tag 'all' |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 ATTRIBUTES |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item id |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Column alias |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has '$.id'; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item name |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
has '$.name'; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item table |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Table association |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
has '$.table' => (associated_class => 'SQL::Entity::Table'); |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item entity |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Entity association |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
has '$.entity' => (associated_class => 'SQL::Entity'); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item expression |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Column expression: |
|
77
|
|
|
|
|
|
|
f.e. col1 || col2 |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
has '$.expression'; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item case_sensitive |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
has '$.case_sensitive' => (default => 1); |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item queryable |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Flag is column can be use in where caluse |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
has '$.queryable' => (default => 1); |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item insertable |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
has '$.insertable' => (default => 1); |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item update_allowed |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
has '$.updatable' => (default => 1); |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item unique |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
has '$.unique'; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=back |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 METHODS |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=over |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item initialise |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub initialise { |
|
132
|
54
|
|
|
54
|
1
|
24819
|
my ($self) = @_; |
|
133
|
54
|
100
|
|
|
|
157
|
$self->set_id($self->name) unless $self->id; |
|
134
|
54
|
100
|
|
|
|
1264
|
if ($self->expression) { |
|
135
|
2
|
|
|
|
|
20
|
$self->insertable(0); |
|
136
|
2
|
|
|
|
|
34
|
$self->updatable(0); |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item as_string |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub as_string { |
|
146
|
62
|
|
|
62
|
1
|
2173
|
my ($self, $source, $join_methods) = @_; |
|
147
|
62
|
|
|
|
|
167
|
my $table = $self->table; |
|
148
|
62
|
100
|
100
|
|
|
757
|
return $self->subquery_to_string($source, $join_methods) |
|
|
|
|
100
|
|
|
|
|
|
149
|
|
|
|
|
|
|
if ($table && $source && $table ne $source); |
|
150
|
60
|
100
|
|
|
|
215
|
my $table_alias = $table ? $table->alias . "." : ''; |
|
151
|
60
|
|
|
|
|
481
|
my $id = $self->id; |
|
152
|
60
|
|
|
|
|
462
|
my $expression = $self->expression; |
|
153
|
60
|
|
|
|
|
450
|
my $name = $self->name; |
|
154
|
60
|
100
|
|
|
|
491
|
my $result = ($expression ? "($expression)" : $table_alias . $name); |
|
155
|
60
|
100
|
66
|
|
|
624
|
$result . ($id && $id ne ($name || '') ? " AS $id": ''); |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item subquery_to_string |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=cut |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub subquery_to_string { |
|
164
|
2
|
|
|
2
|
1
|
5
|
my ($self, $source, $join_methods) = @_; |
|
165
|
2
|
50
|
|
|
|
6
|
return () unless $self->entity; |
|
166
|
2
|
|
|
|
|
22
|
my $table = $self->table; |
|
167
|
2
|
|
|
|
|
19
|
my $id = $self->id; |
|
168
|
2
|
50
|
|
|
|
21
|
my $table_alias = $table ? $table->alias . "." : ''; |
|
169
|
2
|
|
|
|
|
21
|
my $table_id = $table->id; |
|
170
|
2
|
|
|
|
|
19
|
my $relationship = $self->entity->to_one_relationship($table_id); |
|
171
|
2
|
|
|
|
|
46
|
my $join_method = $join_methods->{$table_id}; |
|
172
|
2
|
100
|
|
|
|
7
|
unless ($join_method) { |
|
173
|
|
|
|
|
|
|
#enforce subquery |
|
174
|
1
|
|
|
|
|
4
|
my ($sql, $bind_variable) = $table->query([$id], $relationship->join_condition($self->entity), undef, {$source->id => 'SUBQUERY'}); |
|
175
|
|
|
|
|
|
|
|
|
176
|
1
|
|
|
|
|
10
|
return "($sql) AS $id"; |
|
177
|
|
|
|
|
|
|
} else { |
|
178
|
1
|
|
|
|
|
4
|
$self->as_string; |
|
179
|
|
|
|
|
|
|
} |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item as_operand |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Returns column as condition operand. |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub as_operand { |
|
190
|
13
|
|
|
13
|
1
|
20
|
my $self = shift; |
|
191
|
13
|
|
|
|
|
38
|
my $table = $self->table; |
|
192
|
13
|
100
|
|
|
|
119
|
my $table_alias = $table ? $table->alias . "." : ''; |
|
193
|
13
|
|
|
|
|
93
|
my $case_sensitive = $self->case_sensitive; |
|
194
|
13
|
50
|
33
|
|
|
131
|
(! $case_sensitive ? 'UPPER(' : '') |
|
|
|
50
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
. $table_alias . ($self->name || $self->expression) |
|
196
|
|
|
|
|
|
|
. (! $case_sensitive ? ')' : ''); |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item sql_column |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=cut |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub sql_column { |
|
204
|
45
|
|
|
45
|
1
|
13553
|
__PACKAGE__->new(@_); |
|
205
|
|
|
|
|
|
|
} |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
1; |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
__END__ |