line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Custom::Query; |
2
|
16
|
|
|
16
|
|
113
|
use Object::Simple -base; |
|
16
|
|
|
|
|
38
|
|
|
16
|
|
|
|
|
94
|
|
3
|
|
|
|
|
|
|
|
4
|
16
|
|
|
16
|
|
1760
|
use DBIx::Custom::Util qw/_array_to_hash _subname _deprecate/; |
|
16
|
|
|
|
|
34
|
|
|
16
|
|
|
|
|
930
|
|
5
|
|
|
|
|
|
|
|
6
|
16
|
|
|
16
|
|
100
|
use Carp 'croak'; |
|
16
|
|
|
|
|
33
|
|
|
16
|
|
|
|
|
8047
|
|
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
|
5275
|
my $self = shift; |
17
|
|
|
|
|
|
|
|
18
|
3196
|
|
|
|
|
4945
|
my $param = $self->{param}; |
19
|
3196
|
|
|
|
|
4599
|
my $columns = $self->{columns}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Create bind values |
22
|
3196
|
|
|
|
|
7047
|
my @bind_values; |
23
|
|
|
|
|
|
|
my %count; |
24
|
3196
|
|
|
|
|
0
|
my %not_exists; |
25
|
3196
|
|
|
|
|
7088
|
for my $column (@$columns) { |
26
|
2587
|
|
|
|
|
4252
|
my $value = $param->{$column}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Bind value |
29
|
2587
|
100
|
|
|
|
4773
|
if(ref $value eq 'ARRAY') { |
30
|
150
|
|
100
|
|
|
472
|
my $i = $count{$column} || 0; |
31
|
150
|
|
100
|
|
|
501
|
$i += $not_exists{$column} || 0; |
32
|
150
|
|
|
|
|
257
|
my $found; |
33
|
150
|
|
|
|
|
385
|
for (my $k = $i; $i < @$value; $k++) { |
34
|
165
|
100
|
|
|
|
335
|
if (ref $value->[$k] eq 'DBIx::Custom::NotExists') { |
35
|
15
|
|
|
|
|
38
|
$not_exists{$column}++; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
150
|
|
|
|
|
353
|
push @bind_values, $value->[$k]; |
39
|
150
|
|
|
|
|
203
|
$found = 1; |
40
|
|
|
|
|
|
|
last |
41
|
150
|
|
|
|
|
253
|
} |
42
|
|
|
|
|
|
|
} |
43
|
150
|
50
|
|
|
|
291
|
next unless $found; |
44
|
|
|
|
|
|
|
} |
45
|
2437
|
|
|
|
|
4282
|
else { push @bind_values, $value } |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Count up |
48
|
2587
|
|
|
|
|
5219
|
$count{$column}++; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Bind type |
52
|
3196
|
100
|
|
|
|
6585
|
if ($self->{bind_type}) { |
53
|
4
|
|
|
|
|
8
|
my @bind_value_types; |
54
|
4
|
|
50
|
|
|
72
|
my $bind_type = $self->bind_type || {}; |
55
|
4
|
|
|
|
|
39
|
for (my $i = 0; $i < @$columns; $i++) { |
56
|
8
|
|
|
|
|
15
|
my $column = $columns->[$i]; |
57
|
8
|
|
|
|
|
22
|
push @bind_value_types, $bind_type->{$column}; |
58
|
|
|
|
|
|
|
} |
59
|
4
|
|
|
|
|
74
|
$self->bind_value_types(\@bind_value_types); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
3192
|
|
|
|
|
5607
|
$self->{bind_value_types} = undef; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Has filter |
66
|
3196
|
100
|
|
|
|
6470
|
if ($self->{_f}) { |
67
|
185
|
|
|
|
|
334
|
my $filter = $self->{_filter}; |
68
|
185
|
|
|
|
|
287
|
my $type_filters = $self->{_type_filters}; |
69
|
|
|
|
|
|
|
|
70
|
185
|
|
|
|
|
502
|
for (my $i = 0; $i < @$columns; $i++) { |
71
|
140
|
|
|
|
|
274
|
my $column = $columns->[$i]; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Filter |
74
|
140
|
100
|
|
|
|
329
|
if ($filter) { |
75
|
66
|
100
|
|
|
|
180
|
if (defined $filter->{$column}) { |
76
|
39
|
|
|
|
|
72
|
my $f = $filter->{$column}; |
77
|
39
|
|
|
|
|
142
|
$bind_values[$i] = $f->($bind_values[$i]); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Type rule |
82
|
|
|
|
|
|
|
my $tf1 = $self->{"_into1"}->{dot}->{$column} |
83
|
140
|
|
100
|
|
|
783
|
|| $type_filters->{1}->{$column}; |
84
|
140
|
100
|
|
|
|
377
|
$bind_values[$i] = $tf1->($bind_values[$i]) if $tf1; |
85
|
|
|
|
|
|
|
my $tf2 = $self->{"_into2"}->{dot}->{$column} |
86
|
140
|
|
66
|
|
|
851
|
|| $type_filters->{2}->{$column}; |
87
|
140
|
100
|
|
|
|
472
|
$bind_values[$i] = $tf2->($bind_values[$i]) if $tf2; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
3196
|
|
|
|
|
10966
|
$self->{bind_values} = \@bind_values; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |