line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Custom::Query; |
2
|
16
|
|
|
16
|
|
96
|
use Object::Simple -base; |
|
16
|
|
|
|
|
21
|
|
|
16
|
|
|
|
|
75
|
|
3
|
|
|
|
|
|
|
|
4
|
16
|
|
|
16
|
|
1352
|
use DBIx::Custom::Util qw/_array_to_hash _subname _deprecate/; |
|
16
|
|
|
|
|
24
|
|
|
16
|
|
|
|
|
730
|
|
5
|
|
|
|
|
|
|
|
6
|
16
|
|
|
16
|
|
76
|
use Carp 'croak'; |
|
16
|
|
|
|
|
24
|
|
|
16
|
|
|
|
|
6383
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'sql'; |
9
|
|
|
|
|
|
|
has 'bind_type'; |
10
|
|
|
|
|
|
|
has 'columns'; |
11
|
|
|
|
|
|
|
has 'param'; |
12
|
|
|
|
|
|
|
has 'bind_values'; |
13
|
|
|
|
|
|
|
has 'bind_value_types'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub build { |
16
|
3194
|
|
|
3194
|
0
|
4042
|
my $self = shift; |
17
|
|
|
|
|
|
|
|
18
|
3194
|
|
|
|
|
3924
|
my $param = $self->{param}; |
19
|
3194
|
|
|
|
|
3774
|
my $columns = $self->{columns}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Create bind values |
22
|
3194
|
|
|
|
|
5818
|
my @bind_values; |
23
|
|
|
|
|
|
|
my %count; |
24
|
3194
|
|
|
|
|
0
|
my %not_exists; |
25
|
3194
|
|
|
|
|
5543
|
for my $column (@$columns) { |
26
|
2587
|
|
|
|
|
3471
|
my $value = $param->{$column}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Bind value |
29
|
2587
|
100
|
|
|
|
3713
|
if(ref $value eq 'ARRAY') { |
30
|
150
|
|
100
|
|
|
361
|
my $i = $count{$column} || 0; |
31
|
150
|
|
100
|
|
|
383
|
$i += $not_exists{$column} || 0; |
32
|
150
|
|
|
|
|
165
|
my $found; |
33
|
150
|
|
|
|
|
290
|
for (my $k = $i; $i < @$value; $k++) { |
34
|
165
|
100
|
|
|
|
250
|
if (ref $value->[$k] eq 'DBIx::Custom::NotExists') { |
35
|
15
|
|
|
|
|
34
|
$not_exists{$column}++; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
150
|
|
|
|
|
290
|
push @bind_values, $value->[$k]; |
39
|
150
|
|
|
|
|
175
|
$found = 1; |
40
|
|
|
|
|
|
|
last |
41
|
150
|
|
|
|
|
177
|
} |
42
|
|
|
|
|
|
|
} |
43
|
150
|
50
|
|
|
|
260
|
next unless $found; |
44
|
|
|
|
|
|
|
} |
45
|
2437
|
|
|
|
|
3471
|
else { push @bind_values, $value } |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Count up |
48
|
2587
|
|
|
|
|
4116
|
$count{$column}++; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Bind type |
52
|
3194
|
100
|
|
|
|
4971
|
if ($self->{bind_type}) { |
53
|
4
|
|
|
|
|
4
|
my @bind_value_types; |
54
|
4
|
|
50
|
|
|
54
|
my $bind_type = $self->bind_type || {}; |
55
|
4
|
|
|
|
|
32
|
for (my $i = 0; $i < @$columns; $i++) { |
56
|
8
|
|
|
|
|
12
|
my $column = $columns->[$i]; |
57
|
8
|
|
|
|
|
18
|
push @bind_value_types, $bind_type->{$column}; |
58
|
|
|
|
|
|
|
} |
59
|
4
|
|
|
|
|
56
|
$self->bind_value_types(\@bind_value_types); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
3190
|
|
|
|
|
4381
|
$self->{bind_value_types} = undef; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Has filter |
66
|
3194
|
100
|
|
|
|
5495
|
if ($self->{_f}) { |
67
|
185
|
|
|
|
|
272
|
my $filter = $self->{_filter}; |
68
|
185
|
|
|
|
|
218
|
my $type_filters = $self->{_type_filters}; |
69
|
|
|
|
|
|
|
|
70
|
185
|
|
|
|
|
405
|
for (my $i = 0; $i < @$columns; $i++) { |
71
|
140
|
|
|
|
|
208
|
my $column = $columns->[$i]; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Filter |
74
|
140
|
100
|
|
|
|
251
|
if ($filter) { |
75
|
66
|
100
|
|
|
|
167
|
if (defined $filter->{$column}) { |
76
|
39
|
|
|
|
|
69
|
my $f = $filter->{$column}; |
77
|
39
|
|
|
|
|
104
|
$bind_values[$i] = $f->($bind_values[$i]); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Type rule |
82
|
|
|
|
|
|
|
my $tf1 = $self->{"_into1"}->{dot}->{$column} |
83
|
140
|
|
100
|
|
|
593
|
|| $type_filters->{1}->{$column}; |
84
|
140
|
100
|
|
|
|
306
|
$bind_values[$i] = $tf1->($bind_values[$i]) if $tf1; |
85
|
|
|
|
|
|
|
my $tf2 = $self->{"_into2"}->{dot}->{$column} |
86
|
140
|
|
66
|
|
|
673
|
|| $type_filters->{2}->{$column}; |
87
|
140
|
100
|
|
|
|
377
|
$bind_values[$i] = $tf2->($bind_values[$i]) if $tf2; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
3194
|
|
|
|
|
8410
|
$self->{bind_values} = \@bind_values; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |