line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# DESCRIPTION |
3
|
|
|
|
|
|
|
# PerlORM - Object relational mapper (ORM) for Perl. PerlORM is Perl |
4
|
|
|
|
|
|
|
# library that implements object-relational mapping. Its features are |
5
|
|
|
|
|
|
|
# much similar to those of Java's Hibernate library, but interface is |
6
|
|
|
|
|
|
|
# much different and easier to use. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# AUTHOR |
9
|
|
|
|
|
|
|
# Alexey V. Akimov |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# COPYRIGHT |
12
|
|
|
|
|
|
|
# Copyright (C) 2005-2006 Alexey V. Akimov |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# This library is free software; you can redistribute it and/or |
15
|
|
|
|
|
|
|
# modify it under the terms of the GNU Lesser General Public |
16
|
|
|
|
|
|
|
# License as published by the Free Software Foundation; either |
17
|
|
|
|
|
|
|
# version 2.1 of the License, or (at your option) any later version. |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
# This library is distributed in the hope that it will be useful, |
20
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
21
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
22
|
|
|
|
|
|
|
# Lesser General Public License for more details. |
23
|
|
|
|
|
|
|
# |
24
|
|
|
|
|
|
|
# You should have received a copy of the GNU Lesser General Public |
25
|
|
|
|
|
|
|
# License along with this library; if not, write to the Free Software |
26
|
|
|
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
27
|
|
|
|
|
|
|
# |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
package ORM::Expr; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$VERSION=0.81; |
32
|
|
|
|
|
|
|
|
33
|
5
|
|
|
5
|
|
2650
|
use ORM::Filter::Cmp; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
133
|
|
34
|
5
|
|
|
5
|
|
2807
|
use ORM::Filter::Group; |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
134
|
|
35
|
5
|
|
|
5
|
|
3326
|
use ORM::Filter::Func; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
149
|
|
36
|
5
|
|
|
5
|
|
3083
|
use ORM::Filter::Interval; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
154
|
|
37
|
5
|
|
|
5
|
|
3261
|
use ORM::Filter::Case; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
2965
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
use overload |
40
|
0
|
|
|
0
|
|
0
|
'<' => sub { ORM::Filter::Cmp->new( '<', _re_args( @_ ) ); }, |
41
|
0
|
|
|
0
|
|
0
|
'<=' => sub { ORM::Filter::Cmp->new( '<=', _re_args( @_ ) ); }, |
42
|
0
|
|
|
0
|
|
0
|
'>' => sub { ORM::Filter::Cmp->new( '>', _re_args( @_ ) ); }, |
43
|
0
|
|
|
0
|
|
0
|
'>=' => sub { ORM::Filter::Cmp->new( '>=', _re_args( @_ ) ); }, |
44
|
|
|
|
|
|
|
'==' => \&_overloaded_eq, |
45
|
|
|
|
|
|
|
'!=' => \&_overloaded_ne, |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
0
|
|
0
|
'lt' => sub { ORM::Filter::Cmp->new( '<', _re_args( @_ ) ); }, |
48
|
0
|
|
|
0
|
|
0
|
'le' => sub { ORM::Filter::Cmp->new( '<=', _re_args( @_ ) ); }, |
49
|
0
|
|
|
0
|
|
0
|
'gt' => sub { ORM::Filter::Cmp->new( '>', _re_args( @_ ) ); }, |
50
|
0
|
|
|
0
|
|
0
|
'ge' => sub { ORM::Filter::Cmp->new( '>=', _re_args( @_ ) ); }, |
51
|
|
|
|
|
|
|
'eq' => \&_overloaded_eq, |
52
|
|
|
|
|
|
|
'ne' => \&_overloaded_ne, |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
0
|
|
0
|
'/' => sub { ORM::Filter::Cmp->new( '/', _re_args( @_ ) ); }, |
55
|
0
|
|
|
0
|
|
0
|
'*' => sub { ORM::Filter::Cmp->new( '*', _re_args( @_ ) ); }, |
56
|
0
|
|
|
0
|
|
0
|
'+' => sub { ORM::Filter::Cmp->new( '+', _re_args( @_ ) ); }, |
57
|
0
|
|
|
0
|
|
0
|
'-' => sub { ORM::Filter::Cmp->new( '-', _re_args( @_ ) ); }, |
58
|
0
|
|
|
0
|
|
0
|
'neg' => sub { ORM::Filter::Func->new( '-', $_[0] ); }, |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
0
|
|
0
|
'&' => sub { ORM::Filter::Group->new( 'AND', _re_args( @_ ) ); }, |
61
|
0
|
|
|
0
|
|
0
|
'|' => sub { ORM::Filter::Group->new( 'OR', _re_args( @_ ) ); }, |
62
|
0
|
|
|
0
|
|
0
|
'!' => sub { ORM::Filter::Func->new( '!', $_[0] ); }, |
63
|
|
|
|
|
|
|
|
64
|
5
|
|
|
5
|
|
36
|
'fallback' => 1; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
425
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
## |
67
|
|
|
|
|
|
|
## CONSTRUCTORS |
68
|
|
|
|
|
|
|
## |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
0
|
|
0
|
sub _lt { ORM::Filter::Cmp->new( '<', _autoshift( @_ ) ); } |
71
|
0
|
|
|
0
|
|
0
|
sub _le { ORM::Filter::Cmp->new( '<=', _autoshift( @_ ) ); } |
72
|
0
|
|
|
0
|
|
0
|
sub _gt { ORM::Filter::Cmp->new( '>', _autoshift( @_ ) ); } |
73
|
0
|
|
|
0
|
|
0
|
sub _ge { ORM::Filter::Cmp->new( '>=', _autoshift( @_ ) ); } |
74
|
0
|
|
|
0
|
|
0
|
sub _eq { ORM::Filter::Cmp->new( '=', _autoshift( @_ ) ); } |
75
|
0
|
|
|
0
|
|
0
|
sub _ne { ORM::Filter::Cmp->new( '!=', _autoshift( @_ ) ); } |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _overloaded_eq |
78
|
|
|
|
|
|
|
{ |
79
|
11
|
50
|
|
11
|
|
36
|
if( defined $_[1] ) |
80
|
|
|
|
|
|
|
{ |
81
|
11
|
|
|
|
|
50
|
ORM::Filter::Cmp->new( '=', _re_args( @_ ) ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else |
84
|
|
|
|
|
|
|
{ |
85
|
0
|
|
|
|
|
0
|
$_[0]->_is_undef; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _overloaded_ne |
90
|
|
|
|
|
|
|
{ |
91
|
0
|
0
|
|
0
|
|
0
|
if( defined $_[1] ) |
92
|
|
|
|
|
|
|
{ |
93
|
0
|
|
|
|
|
0
|
ORM::Filter::Cmp->new( '!=', _re_args( @_ ) ); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
else |
96
|
|
|
|
|
|
|
{ |
97
|
0
|
|
|
|
|
0
|
$_[0]->_is_defined; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
0
|
|
0
|
sub _div { ORM::Filter::Cmp->new( '/', _autoshift( @_ ) ); } |
102
|
0
|
|
|
0
|
|
0
|
sub _mul { ORM::Filter::Cmp->new( '*', _autoshift( @_ ) ); } |
103
|
0
|
|
|
0
|
|
0
|
sub _add { ORM::Filter::Cmp->new( '+', _autoshift( @_ ) ); } |
104
|
0
|
|
|
0
|
|
0
|
sub _sub { ORM::Filter::Cmp->new( '-', _autoshift( @_ ) ); } |
105
|
0
|
|
|
0
|
|
0
|
sub _neg { ORM::Filter::Func->new( '-', _autoshift( @_ ) ); } |
106
|
|
|
|
|
|
|
|
107
|
6
|
|
|
6
|
|
22
|
sub _and { ORM::Filter::Group->new( 'AND', _autoshift( @_ ) ); } |
108
|
0
|
|
|
0
|
|
0
|
sub _or { ORM::Filter::Group->new( 'OR', _autoshift( @_ ) ); } |
109
|
0
|
|
|
0
|
|
0
|
sub _not { ORM::Filter::Func->new( 'NOT', _autoshift( @_ ) ); } |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
0
|
|
0
|
sub _brackets { shift; ORM::Filter::Func->new( '', @_ ); } |
|
0
|
|
|
|
|
0
|
|
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
0
|
|
0
|
sub _func { shift; ORM::Filter::Func->new( @_ ); } |
|
0
|
|
|
|
|
0
|
|
114
|
0
|
|
|
0
|
|
0
|
sub _if { shift; ORM::Filter::Func->new( 'IF', @_ ); } |
|
0
|
|
|
|
|
0
|
|
115
|
0
|
|
|
0
|
|
0
|
sub _case { shift; ORM::Filter::Case->new( @_ ); } |
|
0
|
|
|
|
|
0
|
|
116
|
0
|
|
|
0
|
|
0
|
sub _list { shift; ORM::Filter::Group->new( ',', @_ ); } |
|
0
|
|
|
|
|
0
|
|
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
0
|
|
0
|
sub _interval_months { shift; ORM::Filter::Interval->new( 'MONTH', $_[0] ); } |
|
0
|
|
|
|
|
0
|
|
119
|
0
|
|
|
0
|
|
0
|
sub _interval_days { shift; ORM::Filter::Interval->new( 'DAY', $_[0] ); } |
|
0
|
|
|
|
|
0
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
## |
122
|
|
|
|
|
|
|
## PROPERTIES |
123
|
|
|
|
|
|
|
## |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
0
|
|
0
|
sub _date_format { ORM::Filter::Func->new( 'DATE_FORMAT', $_[0], $_[1] ); } |
126
|
0
|
|
|
0
|
|
0
|
sub _time { ORM::Filter::Func->new( 'TIME', $_[0] ); } |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
0
|
|
0
|
sub _bit_and { ORM::Filter::Cmp->new( '&', _autoshift( @_ ) ); } |
129
|
0
|
|
|
0
|
|
0
|
sub _bit_or { ORM::Filter::Cmp->new( '|', _autoshift( @_ ) ); } |
130
|
0
|
|
|
0
|
|
0
|
sub _match { ORM::Filter::Cmp->new( 'REGEXP', @_ ); } |
131
|
0
|
|
|
0
|
|
0
|
sub _regexp { ORM::Filter::Cmp->new( 'REGEXP', @_ ); } |
132
|
0
|
|
|
0
|
|
0
|
sub _like { ORM::Filter::Cmp->new( 'LIKE', @_ ); } |
133
|
1
|
|
|
1
|
|
6
|
sub _append { $_[0]->_tjoin->null_class->_db->_func_concat( @_ ); } |
134
|
0
|
|
|
0
|
|
0
|
sub _length { ORM::Filter::Func->new( 'LENGTH', $_[0] ); } |
135
|
0
|
|
|
0
|
|
0
|
sub _is_undef { ORM::Filter::Cmp->new( 'IS', $_[0], undef ); } |
136
|
0
|
|
|
0
|
|
0
|
sub _is_defined { ORM::Filter::Cmp->new( 'IS NOT', $_[0], undef ); } |
137
|
0
|
|
|
0
|
|
0
|
sub _set_to { ORM::Filter::Cmp->new( '=', @_ ); } |
138
|
|
|
|
|
|
|
sub _substr |
139
|
|
|
|
|
|
|
{ |
140
|
0
|
0
|
|
0
|
|
0
|
if( defined $_[2] ) |
141
|
|
|
|
|
|
|
{ |
142
|
0
|
|
|
|
|
0
|
ORM::Filter::Func->new( 'SUBSTRING', $_[0], $_[1]+1, $_[2] ); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
else |
145
|
|
|
|
|
|
|
{ |
146
|
0
|
|
|
|
|
0
|
ORM::Filter::Func->new( 'SUBSTRING', $_[0], $_[1]+1 ); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
sub _replace |
150
|
|
|
|
|
|
|
{ |
151
|
0
|
|
|
0
|
|
0
|
ORM::Filter::Func->new( 'REPLACE', $_[0], $_[1], $_[2] ); |
152
|
|
|
|
|
|
|
} |
153
|
0
|
|
|
0
|
|
0
|
sub _between { ( $_[0] >= $_[1] ) & ( $_[0] <= $_[2] ); } |
154
|
|
|
|
|
|
|
sub _in |
155
|
|
|
|
|
|
|
{ |
156
|
0
|
|
|
0
|
|
0
|
my $op1 = shift; |
157
|
|
|
|
|
|
|
|
158
|
0
|
0
|
|
|
|
0
|
if( @_ ) |
159
|
|
|
|
|
|
|
{ |
160
|
0
|
|
|
|
|
0
|
my $op2 = ORM::Expr->_brackets( @_ ); |
161
|
0
|
|
|
|
|
0
|
ORM::Filter::Cmp->new( 'IN', $op1, $op2 ); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
else |
164
|
|
|
|
|
|
|
{ |
165
|
0
|
|
|
|
|
0
|
ORM::Filter::Cmp->new( '=', 1, 2 ); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
## |
170
|
|
|
|
|
|
|
## PROPERTIES to use with ORM->stat |
171
|
|
|
|
|
|
|
## |
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
0
|
|
0
|
sub _sum { ORM::Filter::Func->new( 'SUM', @_ ); } |
174
|
0
|
|
|
0
|
|
0
|
sub _max { ORM::Filter::Func->new( 'MAX', @_ ); } |
175
|
0
|
|
|
0
|
|
0
|
sub _min { ORM::Filter::Func->new( 'MIN', @_ ); } |
176
|
0
|
|
|
0
|
|
0
|
sub _count { ORM::Filter::Func->new( 'COUNT', @_ ); } |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
## |
179
|
|
|
|
|
|
|
## PROTECTED |
180
|
|
|
|
|
|
|
## |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
0
|
|
0
|
sub _tjoin { die "You forget to override '_tjoin' in '$_[0]'"; } |
183
|
0
|
|
|
0
|
|
0
|
sub _sql_str { die "You forget to override '_sql_str' in '$_[0]'"; } |
184
|
11
|
50
|
|
11
|
|
109
|
sub _re_args { $_[2] ? ( $_[1], $_[0] ) : ( $_[0], $_[1] ); } |
185
|
6
|
50
|
|
6
|
|
31
|
sub _autoshift { ( ! ref $_[0] && shift @_ ); @_; } |
|
6
|
|
|
|
|
41
|
|