line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Custom::Query; |
2
|
16
|
|
|
16
|
|
115
|
use Object::Simple -base; |
|
16
|
|
|
|
|
33
|
|
|
16
|
|
|
|
|
100
|
|
3
|
|
|
|
|
|
|
|
4
|
16
|
|
|
16
|
|
1820
|
use DBIx::Custom::Util qw/_array_to_hash _subname _deprecate/; |
|
16
|
|
|
|
|
31
|
|
|
16
|
|
|
|
|
930
|
|
5
|
|
|
|
|
|
|
|
6
|
16
|
|
|
16
|
|
95
|
use Carp 'croak'; |
|
16
|
|
|
|
|
44
|
|
|
16
|
|
|
|
|
8061
|
|
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
|
3196
|
|
|
3196
|
0
|
5350
|
my $self = shift; |
17
|
|
|
|
|
|
|
|
18
|
3196
|
|
|
|
|
4894
|
my $param = $self->{param}; |
19
|
3196
|
|
|
|
|
4661
|
my $columns = $self->{columns}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Create bind values |
22
|
3196
|
|
|
|
|
7376
|
my @bind_values; |
23
|
|
|
|
|
|
|
my %count; |
24
|
3196
|
|
|
|
|
0
|
my %not_exists; |
25
|
3196
|
|
|
|
|
7039
|
for my $column (@$columns) { |
26
|
2587
|
|
|
|
|
4075
|
my $value = $param->{$column}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Bind value |
29
|
2587
|
100
|
|
|
|
4720
|
if(ref $value eq 'ARRAY') { |
30
|
150
|
|
100
|
|
|
423
|
my $i = $count{$column} || 0; |
31
|
150
|
|
100
|
|
|
435
|
$i += $not_exists{$column} || 0; |
32
|
150
|
|
|
|
|
199
|
my $found; |
33
|
150
|
|
|
|
|
357
|
for (my $k = $i; $i < @$value; $k++) { |
34
|
165
|
100
|
|
|
|
334
|
if (ref $value->[$k] eq 'DBIx::Custom::NotExists') { |
35
|
15
|
|
|
|
|
38
|
$not_exists{$column}++; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
150
|
|
|
|
|
253
|
push @bind_values, $value->[$k]; |
39
|
150
|
|
|
|
|
194
|
$found = 1; |
40
|
|
|
|
|
|
|
last |
41
|
150
|
|
|
|
|
251
|
} |
42
|
|
|
|
|
|
|
} |
43
|
150
|
50
|
|
|
|
296
|
next unless $found; |
44
|
|
|
|
|
|
|
} |
45
|
2437
|
|
|
|
|
4153
|
else { push @bind_values, $value } |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Count up |
48
|
2587
|
|
|
|
|
5248
|
$count{$column}++; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Bind type |
52
|
3196
|
100
|
|
|
|
6416
|
if ($self->{bind_type}) { |
53
|
4
|
|
|
|
|
6
|
my @bind_value_types; |
54
|
4
|
|
50
|
|
|
71
|
my $bind_type = $self->bind_type || {}; |
55
|
4
|
|
|
|
|
41
|
for (my $i = 0; $i < @$columns; $i++) { |
56
|
8
|
|
|
|
|
15
|
my $column = $columns->[$i]; |
57
|
8
|
|
|
|
|
24
|
push @bind_value_types, $bind_type->{$column}; |
58
|
|
|
|
|
|
|
} |
59
|
4
|
|
|
|
|
73
|
$self->bind_value_types(\@bind_value_types); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
3192
|
|
|
|
|
5507
|
$self->{bind_value_types} = undef; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Has filter |
66
|
3196
|
100
|
|
|
|
6839
|
if ($self->{_f}) { |
67
|
185
|
|
|
|
|
287
|
my $filter = $self->{_filter}; |
68
|
185
|
|
|
|
|
292
|
my $type_filters = $self->{_type_filters}; |
69
|
|
|
|
|
|
|
|
70
|
185
|
|
|
|
|
566
|
for (my $i = 0; $i < @$columns; $i++) { |
71
|
140
|
|
|
|
|
283
|
my $column = $columns->[$i]; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Filter |
74
|
140
|
100
|
|
|
|
301
|
if ($filter) { |
75
|
66
|
100
|
|
|
|
163
|
if (defined $filter->{$column}) { |
76
|
39
|
|
|
|
|
92
|
my $f = $filter->{$column}; |
77
|
39
|
|
|
|
|
139
|
$bind_values[$i] = $f->($bind_values[$i]); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Type rule |
82
|
|
|
|
|
|
|
my $tf1 = $self->{"_into1"}->{dot}->{$column} |
83
|
140
|
|
100
|
|
|
708
|
|| $type_filters->{1}->{$column}; |
84
|
140
|
100
|
|
|
|
350
|
$bind_values[$i] = $tf1->($bind_values[$i]) if $tf1; |
85
|
|
|
|
|
|
|
my $tf2 = $self->{"_into2"}->{dot}->{$column} |
86
|
140
|
|
66
|
|
|
830
|
|| $type_filters->{2}->{$column}; |
87
|
140
|
100
|
|
|
|
458
|
$bind_values[$i] = $tf2->($bind_values[$i]) if $tf2; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
3196
|
|
|
|
|
10571
|
$self->{bind_values} = \@bind_values; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |