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::Filter::Case; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$VERSION=0.8; |
32
|
|
|
|
|
|
|
|
33
|
5
|
|
|
5
|
|
27
|
use overload 'fallback' => 1; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
30
|
|
34
|
5
|
|
|
5
|
|
264
|
use base 'ORM::Filter'; |
|
5
|
|
|
|
|
27
|
|
|
5
|
|
|
|
|
3423
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
## |
37
|
|
|
|
|
|
|
## CONSTRUCTORS |
38
|
|
|
|
|
|
|
## |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub new |
41
|
|
|
|
|
|
|
{ |
42
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
43
|
0
|
|
|
|
|
|
my $self = {}; |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if( ref $_[0] ne 'ARRAY' ) |
46
|
|
|
|
|
|
|
{ |
47
|
0
|
|
|
|
|
|
$self->{value} = shift; |
48
|
0
|
0
|
|
|
|
|
unless( UNIVERSAL::isa( $self->{value}, 'ORM::Expr' ) ) |
49
|
|
|
|
|
|
|
{ |
50
|
0
|
|
|
|
|
|
$self->{value} = ORM::Const->new( $self->{value} ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
@{$self->{case}} = @_; |
|
0
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if( ref $self->{case}[-1] ne 'ARRAY' ) |
57
|
|
|
|
|
|
|
{ |
58
|
0
|
|
|
|
|
|
$self->{else} = pop @{$self->{case}}; |
|
0
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return bless $self, $class; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
## |
65
|
|
|
|
|
|
|
## PROPERTIES |
66
|
|
|
|
|
|
|
## |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _sql_str |
69
|
|
|
|
|
|
|
{ |
70
|
0
|
|
|
0
|
|
|
my $self = shift; |
71
|
0
|
|
|
|
|
|
my %arg = @_; |
72
|
0
|
|
|
|
|
|
my $sql; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
$sql .= 'CASE'; |
75
|
0
|
0
|
|
|
|
|
$sql .= ' '.$self->{value}->_sql_str( %arg ) if( $self->{value} ); |
76
|
0
|
|
|
|
|
|
$sql .= "\n"; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
for my $case ( @{$self->{case}} ) |
|
0
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
{ |
80
|
0
|
|
|
|
|
|
$sql .= |
81
|
|
|
|
|
|
|
$arg{ident} |
82
|
|
|
|
|
|
|
. ' WHEN '.$self->scalar2sql( $case->[0], $arg{tjoin}, $arg{ident}.' ' ) |
83
|
|
|
|
|
|
|
. ' THEN '.$self->scalar2sql( $case->[1], $arg{tjoin}, $arg{ident}.' ' ) . "\n"; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
if( exists $self->{else} ) |
87
|
|
|
|
|
|
|
{ |
88
|
0
|
|
|
|
|
|
$sql .= $arg{ident}.' ELSE '.$self->scalar2sql( $self->{else}, $arg{tjoin}, $arg{ident}.' ' )."\n"; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
$sql .= $arg{ident}." END"; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
return $sql; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _tjoin |
97
|
|
|
|
|
|
|
{ |
98
|
0
|
|
|
0
|
|
|
my $self = shift; |
99
|
0
|
|
|
|
|
|
my $tjoin = ORM::Tjoin->new; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
for my $arg ( $self->{value}, $self->{else} ) |
102
|
|
|
|
|
|
|
{ |
103
|
0
|
0
|
|
|
|
|
if( UNIVERSAL::isa( $arg, 'ORM::Expr' ) ) |
104
|
|
|
|
|
|
|
{ |
105
|
0
|
|
|
|
|
|
$tjoin->merge( $arg->_tjoin ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
for my $arg ( @{$self->{case}} ) |
|
0
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
{ |
111
|
0
|
0
|
|
|
|
|
if( UNIVERSAL::isa( $arg->[0], 'ORM::Expr' ) ) |
112
|
|
|
|
|
|
|
{ |
113
|
0
|
|
|
|
|
|
$tjoin->merge( $arg->[0]->_tjoin ); |
114
|
|
|
|
|
|
|
} |
115
|
0
|
0
|
|
|
|
|
if( UNIVERSAL::isa( $arg->[1], 'ORM::Expr' ) ) |
116
|
|
|
|
|
|
|
{ |
117
|
0
|
|
|
|
|
|
$tjoin->merge( $arg->[1]->_tjoin ); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
return $tjoin; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
## |
125
|
|
|
|
|
|
|
## METHODS |
126
|
|
|
|
|
|
|
## |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub add_case |
129
|
|
|
|
|
|
|
{ |
130
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
131
|
0
|
|
|
|
|
|
my $case = shift; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
push @{$self->{case}}, $case; |
|
0
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
} |