line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::DBI::Handler; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1951
|
use Catmandu::Sane; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
26
|
|
4
|
3
|
|
|
3
|
|
749
|
use Moo::Role; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
23
|
|
5
|
3
|
|
|
3
|
|
1564
|
use namespace::clean; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
21
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = "0.11"; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
requires 'create_table'; |
10
|
|
|
|
|
|
|
requires 'add_row'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub select_sql { |
13
|
1
|
|
|
1
|
0
|
4
|
my ($self, $bag, $start, $limit, $where) = @_; |
14
|
1
|
|
|
|
|
6
|
my $id_field = $bag->mapping->{_id}->{column}; |
15
|
1
|
|
|
|
|
4
|
my $q_id_field = $bag->_quote_id($id_field); |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
31
|
my $sql = "SELECT * FROM " . $bag->_quote_id($bag->name); |
18
|
1
|
50
|
|
|
|
29
|
$sql .= " WHERE $where" if $where; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
33
|
|
|
12
|
my $default_order = $bag->default_order // $bag->store->default_order; |
21
|
|
|
|
|
|
|
|
22
|
1
|
50
|
|
|
|
5
|
if (defined $default_order) { |
23
|
1
|
50
|
|
|
|
15
|
if ($default_order eq 'ID') { |
|
|
0
|
|
|
|
|
|
24
|
1
|
|
|
|
|
6
|
$sql .= " ORDER BY $q_id_field"; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
elsif ($default_order eq 'NONE') { |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# no nothing |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
0
|
|
|
|
|
0
|
$sql .= " ORDER BY $default_order"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
1
|
|
|
|
|
5
|
$sql .= " LIMIT $limit OFFSET $start"; |
35
|
1
|
|
|
|
|
8
|
$sql; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub count_sql { |
39
|
8
|
|
|
8
|
0
|
192
|
my ($self, $bag, $start, $total, $where) = @_; |
40
|
8
|
|
|
|
|
33
|
my $name = $bag->name; |
41
|
|
|
|
|
|
|
|
42
|
8
|
100
|
100
|
|
|
69
|
return "SELECT COUNT(*) FROM " . $bag->_quote_id($name) |
|
|
|
100
|
|
|
|
|
43
|
|
|
|
|
|
|
unless $total || $start || $where; |
44
|
|
|
|
|
|
|
|
45
|
4
|
|
|
|
|
21
|
my $sql = "SELECT COUNT(*) FROM (SELECT * FROM " . $bag->_quote_id($name); |
46
|
4
|
100
|
|
|
|
118
|
if ($where) { |
47
|
3
|
|
|
|
|
10
|
$sql .= " WHERE $where"; |
48
|
|
|
|
|
|
|
} |
49
|
4
|
100
|
|
|
|
14
|
if ($total) { |
|
|
100
|
|
|
|
|
|
50
|
2
|
|
|
|
|
8
|
$sql .= " LIMIT $total"; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif ($start) { # no offset without limit |
53
|
1
|
|
|
|
|
7
|
$sql .= " LIMIT " . $bag->_max_limit; |
54
|
|
|
|
|
|
|
} |
55
|
4
|
100
|
|
|
|
66
|
if ($start) { |
56
|
3
|
|
|
|
|
8
|
$sql .= " OFFSET $start"; |
57
|
|
|
|
|
|
|
} |
58
|
4
|
|
|
|
|
8
|
$sql .= ") AS q"; |
59
|
|
|
|
|
|
|
|
60
|
4
|
|
|
|
|
22
|
$sql; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|