blib/lib/DBIO/SQLite/Introspect/Indexes.pm

filter: Statementstmt 100% 28 / 28 Branchbran 100% 8 / 8 Conditioncond 100% 8 / 8 MC/DCmcdc 100% 5 / 5 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 100% 54 / 54 CC 10 SCAR 20.7
CC
10
Cov
100%
fetch
10.0
BEGIN
1.0
BEGIN
1.0
CRAP 7.9
« blib/lib/DBIO/SQLite/Diff/View.pm ↑ Summary blib/lib/DBIO/SQLite/Introspect/Tables.pm »
1 package DBIO::SQLite::Introspect::Indexes;
2 # ABSTRACT: Introspect SQLite indexes
3  
4 193 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 193 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 193 our $VERSION = '0.900007';
8  
9 193 ▶use DBIO::SQLite::Util qw(quote_identifier selectall_hashrefs sql_tokens);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12  
13 755 ▶sub fetch {
Subroutine fetch: called CC=10 SCAR=23.0
Pod documented
14 755 my ($class, $dbh, $tables) = @_;
15 755 my %indexes;
16  
17 # Lookup of CREATE INDEX statements from sqlite_master so we can detect
18 # partial indexes and recover the original column expressions.
19 755 my $sql_lookup = $dbh->selectall_hashref(
20 q{SELECT name, sql FROM sqlite_master WHERE type = 'index'},
21 'name',
22 );
23  
24 755 for my $table_name (sort keys %$tables) {
25 1459 my $list = selectall_hashrefs($dbh,
26 sprintf('PRAGMA index_list(%s)', quote_identifier($table_name)));
27  
28 1459 my %t_idx;
29 1459 for my $idx (@$list) {
30 my $info = selectall_hashrefs($dbh,
31 420 sprintf('PRAGMA index_info(%s)', quote_identifier($idx->{name})));
32 420 ▶ my @cols = map { $_->{name} // '' } sort { $a->{seqno} <=> $b->{seqno} } @$info;
Condition100%2/2
$_->{"name"} // ""
l!l
54016
MC/DC100%1/1
$_->{"name"} // ""
$_->{"name"}
Truth table100%2/2
A
A= $_->{"name"}
Aresult
11
00
33  
34 my $sql = $sql_lookup->{ $idx->{name} }
35 ? $sql_lookup->{ $idx->{name} }{sql}
36 420 ▶ : undef;
Branch: 1 branch
BranchTrueFalseTotal
$$sql_lookup{$idx->{'name'}} ? : 384 36 420
37  
38 # The keyword, not the letters: an index, a table or a column may be
39 # named "where", and stands in the statement between quotes then.
40 my $partial = ($sql && grep {
41 420 ▶ $_->[0] eq 'word' && uc $_->[1] eq 'WHERE'
Branch: 1 branch
BranchTrueFalseTotal
$sql && grep({$_->[0] eq 'word' and uc $_->[1] eq 'WHERE';} sql_tokens($sql)) ? : 43 377 420
Condition100%6/6
$sql and grep {$_->[0] eq "word" and uc $_->[1] eq "WHERE";} sql_tokens($sql)
!ll&&!rl&&r
23014743
$_->[0] eq 'word' && uc $_->[1] eq 'WHERE'
!ll&&!rl&&r
223987743
MC/DC100%2/2
$sql and grep {$_->[0] eq "word" and uc $_->[1] eq "WHERE";} sql_tokens($sql)
$sql grep {$_->[0] eq "word" and uc $_->[1] eq "WHERE";} sql_tokens($sql)
MC/DC100%2/2
$_->[0] eq 'word' && uc $_->[1] eq 'WHERE'
$_->[0] eq 'word' uc $_->[1] eq 'WHERE'
Truth table100%3/3
A and B
A= $sqlB= grep {$_->[0] eq "word" and uc $_->[1] eq "WHERE";} sql_tokens($sql)
ABresult
0X0
100
111
Truth table100%3/3
A && B
A= $_->[0] eq 'word'B= uc $_->[1] eq 'WHERE'
ABresult
0X0
100
111
42 } sql_tokens($sql)) ? 1 : 0;
43  
44 $t_idx{ $idx->{name} } = {
45 index_name => $idx->{name},
46 is_unique => $idx->{unique} ? 1 : 0,
47 columns => \@cols,
48 sql => $sql,
49 origin => $idx->{origin},
50 420 ▶ partial => $partial,
Branch: 1 branch
BranchTrueFalseTotal
$idx->{'unique'} ? : 271 149 420
51 };
52 }
53 1459 ▶ $indexes{$table_name} = \%t_idx if %t_idx;
Branch: 1 branch
BranchTrueFalseTotal
if %t_idx 263 1196 1459
54 }
55  
56 755 return \%indexes;
57 }
58  
59 193 1;
60  
61 __END__
« blib/lib/DBIO/SQLite/Diff/View.pm ↑ Summary blib/lib/DBIO/SQLite/Introspect/Tables.pm »