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::Order; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$VERSION=0.8; |
32
|
|
|
|
|
|
|
|
33
|
5
|
|
|
5
|
|
3107
|
use ORM::Metaprop; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
3109
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
## use: $order = $class->new |
36
|
|
|
|
|
|
|
## ( |
37
|
|
|
|
|
|
|
## ( |
38
|
|
|
|
|
|
|
## ORM::Metaprop |
39
|
|
|
|
|
|
|
## | [ORM::Metaprop, ('ASC'|'DESC')] |
40
|
|
|
|
|
|
|
## ), |
41
|
|
|
|
|
|
|
## ... |
42
|
|
|
|
|
|
|
## ) |
43
|
|
|
|
|
|
|
## |
44
|
|
|
|
|
|
|
## OR |
45
|
|
|
|
|
|
|
## |
46
|
|
|
|
|
|
|
## $order = $class->new( STRING ) |
47
|
|
|
|
|
|
|
## |
48
|
|
|
|
|
|
|
sub new |
49
|
|
|
|
|
|
|
{ |
50
|
1
|
|
|
1
|
0
|
3
|
my $class = shift; |
51
|
1
|
|
|
|
|
2
|
my @order; |
52
|
|
|
|
|
|
|
|
53
|
1
|
50
|
|
|
|
4
|
if( ref $_[0] ) |
54
|
|
|
|
|
|
|
{ |
55
|
1
|
|
|
|
|
3
|
@order = @_; |
56
|
|
|
|
|
|
|
# Validating $arg{order} |
57
|
1
|
|
|
|
|
19
|
for( my $i=0; $i<@order; $i++ ) |
58
|
|
|
|
|
|
|
{ |
59
|
1
|
50
|
|
|
|
6
|
if( ref $order[$i] eq 'ARRAY' ) |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
0
|
|
|
|
0
|
$order[$i][1] = ( $order[$i][1] =~ /^DESC$/i ) ? 'DESC' : 'ASC'; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else |
64
|
|
|
|
|
|
|
{ |
65
|
1
|
|
|
|
|
6
|
$order[$i] = [ $order[$i], 'ASC' ]; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else |
70
|
|
|
|
|
|
|
{ |
71
|
0
|
|
|
|
|
0
|
my %arg = @_; |
72
|
0
|
|
|
|
|
0
|
my $obj_class = $arg{class}; |
73
|
0
|
|
|
|
|
0
|
my $order_str = $arg{sort_str}; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
for my $field ( split /[\,]+/, $order_str ) |
76
|
|
|
|
|
|
|
{ |
77
|
0
|
|
|
|
|
0
|
my( $prop, $dir ) = split /\s/, $field; |
78
|
0
|
0
|
|
|
|
0
|
push @order, |
79
|
|
|
|
|
|
|
[ |
80
|
|
|
|
|
|
|
$obj_class->M->_prop( $prop ), |
81
|
|
|
|
|
|
|
( ( $dir =~ /^DESC$/i ) ? 'DESC' : 'ASC' ), |
82
|
|
|
|
|
|
|
]; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
1
|
50
|
|
|
|
13
|
return scalar(@order) ? ( bless { order=>\@order }, $class ) : undef; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _tjoin |
89
|
|
|
|
|
|
|
{ |
90
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
91
|
|
|
|
|
|
|
|
92
|
1
|
50
|
|
|
|
5
|
if( !$self->{tjoin} ) |
93
|
|
|
|
|
|
|
{ |
94
|
1
|
|
|
|
|
6
|
$self->{tjoin} = ORM::Tjoin->new; |
95
|
1
|
|
|
|
|
3
|
for my $prop ( @{$self->{order}} ) |
|
1
|
|
|
|
|
4
|
|
96
|
|
|
|
|
|
|
{ |
97
|
1
|
|
|
|
|
8
|
$self->{tjoin}->merge( $prop->[0]->_tjoin ); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
1
|
|
|
|
|
6
|
return $self->{tjoin}; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub sql_order_by |
105
|
|
|
|
|
|
|
{ |
106
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
107
|
1
|
|
|
|
|
4
|
my %arg = @_; |
108
|
1
|
|
|
|
|
1
|
my $sql; |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
2
|
for my $prop ( @{$self->{order}} ) |
|
1
|
|
|
|
|
4
|
|
111
|
|
|
|
|
|
|
{ |
112
|
1
|
|
|
|
|
8
|
$sql .= $prop->[0]->_sql_str( tjoin=>$arg{tjoin} ) .' '. $prop->[1] .','; |
113
|
|
|
|
|
|
|
} |
114
|
1
|
|
|
|
|
3
|
chop $sql; |
115
|
|
|
|
|
|
|
|
116
|
1
|
|
|
|
|
7
|
return $sql; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub cond |
120
|
|
|
|
|
|
|
{ |
121
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
122
|
0
|
|
|
|
|
|
my $index = shift; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
return $self->{order}[$index]; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub conds_amount |
128
|
|
|
|
|
|
|
{ |
129
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
130
|
0
|
|
|
|
|
|
return scalar @{$self->{order}}; |
|
0
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
} |