line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
3
|
|
|
3
|
|
2582
|
use Moo; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
24
|
|
4
|
3
|
|
|
3
|
|
734
|
use namespace::clean; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
31
|
|
5
|
3
|
|
|
3
|
|
1314
|
|
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
23
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.12"; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with 'Catmandu::Store::DBI::Handler'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my ($self, $map, $bag) = @_; |
11
|
|
|
|
|
|
|
my $col = $map->{column}; |
12
|
12
|
|
|
12
|
|
71
|
my $dbh = $bag->store->dbh; |
13
|
12
|
|
|
|
|
49
|
my $sql = $dbh->quote_identifier($col) . " "; |
14
|
12
|
|
|
|
|
40
|
if ($map->{type} eq 'string') { |
15
|
12
|
|
|
|
|
41
|
$sql .= 'TEXT'; |
16
|
12
|
100
|
|
|
|
344
|
} |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
17
|
9
|
|
|
|
|
17
|
elsif ($map->{type} eq 'integer') { |
18
|
|
|
|
|
|
|
$sql .= 'INTEGER'; |
19
|
|
|
|
|
|
|
} |
20
|
0
|
|
|
|
|
0
|
elsif ($map->{type} eq 'binary') { |
21
|
|
|
|
|
|
|
$sql .= 'BLOB'; |
22
|
|
|
|
|
|
|
} |
23
|
3
|
|
|
|
|
8
|
else { |
24
|
|
|
|
|
|
|
Catmandu::Error->throw("Unknown type '$map->{type}'"); |
25
|
|
|
|
|
|
|
} |
26
|
0
|
|
|
|
|
0
|
if ($map->{unique}) { |
27
|
|
|
|
|
|
|
$sql .= " UNIQUE"; |
28
|
12
|
100
|
|
|
|
29
|
} |
29
|
5
|
|
|
|
|
69
|
if ($map->{required}) { |
30
|
|
|
|
|
|
|
$sql .= " NOT NULL"; |
31
|
12
|
100
|
|
|
|
33
|
} |
32
|
5
|
|
|
|
|
12
|
$sql; |
33
|
|
|
|
|
|
|
} |
34
|
12
|
|
|
|
|
40
|
|
35
|
|
|
|
|
|
|
my ($self, $bag) = @_; |
36
|
|
|
|
|
|
|
my $mapping = $bag->mapping; |
37
|
|
|
|
|
|
|
my $dbh = $bag->store->dbh; |
38
|
5
|
|
|
5
|
0
|
211
|
my $name = $bag->name; |
39
|
5
|
|
|
|
|
24
|
my $q_name = $dbh->quote_identifier($name); |
40
|
5
|
|
|
|
|
23
|
|
41
|
5
|
|
|
|
|
20
|
my $sql |
42
|
5
|
|
|
|
|
54
|
= "CREATE TABLE IF NOT EXISTS $q_name(" |
43
|
|
|
|
|
|
|
. join(',', map {$self->_column_sql($_, $bag)} values %$mapping) |
44
|
|
|
|
|
|
|
. ")"; |
45
|
|
|
|
|
|
|
|
46
|
5
|
|
|
|
|
4784
|
$dbh->do($sql) or Catmandu::Error->throw($dbh->errstr); |
|
12
|
|
|
|
|
27
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
for my $map (values %$mapping) { |
49
|
5
|
50
|
|
|
|
30
|
next if $map->{unique} || !$map->{index}; |
50
|
|
|
|
|
|
|
my $col = $map->{column}; |
51
|
5
|
|
|
|
|
25733
|
my $q_col = $dbh->quote_identifier($col); |
52
|
12
|
50
|
66
|
|
|
78
|
my $q_idx = $dbh->quote_identifier("${name}_${col}_idx"); |
53
|
0
|
|
|
|
|
0
|
my $idx_sql |
54
|
0
|
|
|
|
|
0
|
= "CREATE INDEX IF NOT EXISTS ${q_idx} ON $q_name($q_col)"; |
55
|
0
|
|
|
|
|
0
|
$dbh->do($idx_sql) or Catmandu::Error->throw($dbh->errstr); |
56
|
0
|
|
|
|
|
0
|
} |
57
|
|
|
|
|
|
|
} |
58
|
0
|
0
|
|
|
|
0
|
|
59
|
|
|
|
|
|
|
my ($self, $bag, $row) = @_; |
60
|
|
|
|
|
|
|
my $dbh = $bag->store->dbh; |
61
|
|
|
|
|
|
|
my @cols = keys %$row; |
62
|
|
|
|
|
|
|
my @q_cols = map {$dbh->quote_identifier($_)} @cols; |
63
|
50
|
|
|
50
|
0
|
113
|
my @values = values %$row; |
64
|
50
|
|
|
|
|
309
|
my $q_name = $dbh->quote_identifier($bag->name); |
65
|
50
|
|
|
|
|
185
|
my $sql |
66
|
50
|
|
|
|
|
136
|
= "INSERT OR REPLACE INTO $q_name(" |
|
101
|
|
|
|
|
1845
|
|
67
|
50
|
|
|
|
|
950
|
. join(',', @q_cols) |
68
|
50
|
|
|
|
|
180
|
. ") VALUES(" |
69
|
50
|
|
|
|
|
1044
|
. join(',', ('?') x @cols) . ")"; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $sth = $dbh->prepare_cached($sql) |
72
|
|
|
|
|
|
|
or Catmandu::Error->throw($dbh->errstr); |
73
|
|
|
|
|
|
|
$sth->execute(@values) or Catmandu::Error->throw($sth->errstr); |
74
|
|
|
|
|
|
|
$sth->finish; |
75
|
50
|
50
|
|
|
|
278
|
} |
76
|
|
|
|
|
|
|
|
77
|
50
|
50
|
|
|
|
219667
|
1; |