line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Alzabo::Runtime; |
2
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
34316
|
use strict; |
|
11
|
|
|
|
|
27
|
|
|
11
|
|
|
|
|
448
|
|
4
|
|
|
|
|
|
|
|
5
|
11
|
|
|
11
|
|
1201
|
use Alzabo; |
|
11
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
237
|
|
6
|
|
|
|
|
|
|
|
7
|
11
|
|
|
11
|
|
6488
|
use Alzabo::Runtime::Column; |
|
11
|
|
|
|
|
33
|
|
|
11
|
|
|
|
|
284
|
|
8
|
11
|
|
|
11
|
|
6513
|
use Alzabo::Runtime::ColumnDefinition; |
|
11
|
|
|
|
|
28
|
|
|
11
|
|
|
|
|
459
|
|
9
|
11
|
|
|
11
|
|
6952
|
use Alzabo::Runtime::ForeignKey; |
|
11
|
|
|
|
|
38
|
|
|
11
|
|
|
|
|
289
|
|
10
|
11
|
|
|
11
|
|
6396
|
use Alzabo::Runtime::Index; |
|
11
|
|
|
|
|
33
|
|
|
11
|
|
|
|
|
266
|
|
11
|
11
|
|
|
11
|
|
6999
|
use Alzabo::Runtime::InsertHandle; |
|
11
|
|
|
|
|
33
|
|
|
11
|
|
|
|
|
339
|
|
12
|
11
|
|
|
11
|
|
20669
|
use Alzabo::Runtime::JoinCursor; |
|
11
|
|
|
|
|
43
|
|
|
11
|
|
|
|
|
339
|
|
13
|
11
|
|
|
11
|
|
7227
|
use Alzabo::Runtime::Row; |
|
11
|
|
|
|
|
44
|
|
|
11
|
|
|
|
|
428
|
|
14
|
11
|
|
|
11
|
|
7568
|
use Alzabo::Runtime::RowCursor; |
|
11
|
|
|
|
|
37
|
|
|
11
|
|
|
|
|
299
|
|
15
|
11
|
|
|
11
|
|
8580
|
use Alzabo::Runtime::Schema; |
|
11
|
|
|
|
|
46
|
|
|
11
|
|
|
|
|
336
|
|
16
|
11
|
|
|
11
|
|
10146
|
use Alzabo::Runtime::Table; |
|
11
|
|
|
|
|
53
|
|
|
11
|
|
|
|
|
360
|
|
17
|
11
|
|
|
11
|
|
95
|
use Alzabo::Utils; |
|
11
|
|
|
|
|
30
|
|
|
11
|
|
|
|
|
251
|
|
18
|
|
|
|
|
|
|
|
19
|
11
|
|
|
11
|
|
65
|
use vars qw($VERSION); |
|
11
|
|
|
|
|
26
|
|
|
11
|
|
|
|
|
10132
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$VERSION = 2.0; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
1; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub import |
26
|
|
|
|
|
|
|
{ |
27
|
15
|
|
|
15
|
|
190
|
shift; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# ignore errors and let them be handled later in the app when it |
30
|
|
|
|
|
|
|
# tries to access the schema. |
31
|
15
|
|
|
|
|
10177
|
eval { Alzabo::Runtime::Schema->load_from_file( name => $_ ); } foreach @_; |
|
0
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub sqlmaker |
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
|
0
|
0
|
|
my ($schema, $p) = @_; |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
my %sqlmaker_p = ( exists $p->{quote_identifiers} ? |
39
|
|
|
|
|
|
|
( quote_identifiers => $p->{quote_identifiers} ) : |
40
|
|
|
|
|
|
|
() |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return $schema->sqlmaker(%sqlmaker_p); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub process_where_clause |
47
|
|
|
|
|
|
|
{ |
48
|
0
|
|
|
0
|
0
|
|
my ($sql, $where) = @_; |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
0
|
|
|
|
$where = [ $where ] |
51
|
|
|
|
|
|
|
unless Alzabo::Utils::is_arrayref( $where->[0] ) || $where->[0] eq '('; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
0
|
|
|
|
my $has_where = |
54
|
|
|
|
|
|
|
( $sql->last_op eq 'where' || $sql->last_op eq 'condition' ) ? 1 : 0; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
_process_conditions( $sql, $has_where, $where, 'where' ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub process_having_clause |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
0
|
0
|
|
my ($sql, $having) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
0
|
|
|
|
$having = [ $having ] |
64
|
|
|
|
|
|
|
unless Alzabo::Utils::is_arrayref( $having->[0] ) || $having->[0] eq '('; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
0
|
|
|
|
my $has_having = |
67
|
|
|
|
|
|
|
( $sql->last_op eq 'having' || $sql->last_op eq 'condition' ) ? 1 : 0; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
_process_conditions( $sql, $has_having, $having, 'having' ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _process_conditions |
73
|
|
|
|
|
|
|
{ |
74
|
0
|
|
|
0
|
|
|
my ($sql, $has_start, $conditions, $needed_op) = @_; |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
0
|
|
|
|
my $needs_op = $sql->last_op eq 'where' || $sql->last_op eq 'having' ? 0 : 1; |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
if ($has_start) |
79
|
|
|
|
|
|
|
{ |
80
|
|
|
|
|
|
|
# wrap this in parens in order to protect from interactions with |
81
|
|
|
|
|
|
|
# join clauses |
82
|
0
|
0
|
|
|
|
|
$sql->and if $needs_op; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$sql->subgroup_start; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$needs_op = 0; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my $x = 0; |
90
|
0
|
|
|
|
|
|
foreach my $clause (@$conditions) |
91
|
|
|
|
|
|
|
{ |
92
|
0
|
0
|
0
|
|
|
|
if (ref $clause) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
93
|
|
|
|
|
|
|
{ |
94
|
0
|
0
|
|
|
|
|
Alzabo::Exception::Params->throw |
95
|
|
|
|
|
|
|
( error => "Individual where clause components must be array references" ) |
96
|
|
|
|
|
|
|
unless Alzabo::Utils::is_arrayref($clause); |
97
|
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
|
Alzabo::Exception::Params->throw |
99
|
|
|
|
|
|
|
( error => "Individual where clause components cannot be empty" ) |
100
|
|
|
|
|
|
|
unless @$clause; |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
if ($needs_op) |
103
|
|
|
|
|
|
|
{ |
104
|
0
|
0
|
0
|
|
|
|
my $op = $x || $has_start ? 'and' : $needed_op; |
105
|
0
|
|
|
|
|
|
$sql->$op(); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$sql->condition(@$clause); |
109
|
0
|
|
|
|
|
|
$needs_op = 1; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
elsif (lc $clause eq 'and' || lc $clause eq 'or') |
112
|
|
|
|
|
|
|
{ |
113
|
0
|
|
|
|
|
|
$sql->$clause(); |
114
|
0
|
|
|
|
|
|
$needs_op = 0; |
115
|
0
|
|
|
|
|
|
next; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
elsif ($clause eq '(') |
118
|
|
|
|
|
|
|
{ |
119
|
0
|
0
|
|
|
|
|
if ($needs_op) |
120
|
|
|
|
|
|
|
{ |
121
|
0
|
0
|
0
|
|
|
|
my $op = $x || $has_start ? 'and' : $needed_op; |
122
|
0
|
|
|
|
|
|
$sql->$op(); |
123
|
|
|
|
|
|
|
} |
124
|
0
|
|
|
|
|
|
$sql->subgroup_start; |
125
|
0
|
|
|
|
|
|
$needs_op = 0; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
elsif ($clause eq ')') |
128
|
|
|
|
|
|
|
{ |
129
|
0
|
|
|
|
|
|
$sql->subgroup_end; |
130
|
0
|
|
|
|
|
|
$needs_op = 1; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
else |
133
|
|
|
|
|
|
|
{ |
134
|
0
|
|
|
|
|
|
Alzabo::Exception::Params->throw( error => "Invalid where clause specification: $clause" ); |
135
|
|
|
|
|
|
|
} |
136
|
0
|
|
|
|
|
|
$x++; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
|
$sql->subgroup_end if $has_start; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub process_order_by_clause |
143
|
|
|
|
|
|
|
{ |
144
|
0
|
|
|
0
|
0
|
|
_process_by_clause(@_, 'order'); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub process_group_by_clause |
148
|
|
|
|
|
|
|
{ |
149
|
0
|
|
|
0
|
0
|
|
_process_by_clause(@_, 'group'); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub _process_by_clause |
153
|
|
|
|
|
|
|
{ |
154
|
0
|
|
|
0
|
|
|
my ($sql, $by, $type) = @_; |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
my @items; |
157
|
0
|
0
|
0
|
|
|
|
if ( Alzabo::Utils::safe_isa( $by, 'Alzabo::Column' ) || Alzabo::Utils::safe_isa( $by, 'Alzabo::SQLMaker::Function' ) ) |
|
|
0
|
|
|
|
|
|
158
|
|
|
|
|
|
|
{ |
159
|
0
|
|
|
|
|
|
@items = $by; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
elsif ( Alzabo::Utils::is_arrayref($by) ) |
162
|
|
|
|
|
|
|
{ |
163
|
0
|
|
|
|
|
|
@items = @$by; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
my $method = "${type}_by"; |
167
|
0
|
|
|
|
|
|
$sql->$method(@items); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
__END__ |