Firebird/Introspect/Indexes.pm

filter: Statementstmt 22.8% 8 / 35 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 66.6% 2 / 3 Podpod 100% 1 / 1 totaltotal 21.1% 11 / 52 CC 8 SCAR 40.6
CC
8
Cov
17%
fetch
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 57.8
↑ Summary Firebird/DDL.pm »
1 package DBIO::Firebird::Introspect::Indexes;
2 # ABSTRACT: Introspect Firebird indexes via rdb$indices / rdb$index_segments
3  
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 our $VERSION = '0.900007';
8  
9  
10  
11 0 ▶sub fetch {
Subroutine fetch: not called CC=8 SCAR=42.8
Pod documented
12 0 my ($class, $dbh, $tables) = @_;
13 0 my %indexes;
14  
15 0 my $sth = $dbh->prepare(q{
16 SELECT i.rdb$index_name, i.rdb$relation_name, i.rdb$unique_flag,
17 iseg.rdb$field_name, iseg.rdb$field_position,
18 i.rdb$index_type
19 FROM rdb$indices i
20 JOIN rdb$index_segments iseg ON i.rdb$index_name = iseg.rdb$index_name
21 WHERE i.rdb$system_flag = 0
22 AND i.rdb$foreign_key IS NULL
23 ORDER BY i.rdb$relation_name, i.rdb$index_name, iseg.rdb$field_position
24 });
25 0 $sth->execute;
26  
27 0 my %idx_info;
28 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
29 0 my $table = $row->{'rdb$relation_name'};
30 0 $table =~ s/\s+$//;
31 0 ▶ next unless exists $tables->{$table};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $tables->{$table} 0 0 0
32  
33 0 my $name = $row->{'rdb$index_name'};
34 0 $name =~ s/\s+$//;
35  
36 $idx_info{$name} //= {
37 index_name => $name,
38 table_name => $table,
39 0 ▶ is_unique => $row->{'rdb$unique_flag'} ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$row->{'rdb$unique_flag'} ? : 0 0 0
Condition0%0/2
$idx_info{$name} //= {"index_name", $name, "table_name", $table, "is_unique", $row->{"rdb\$unique_flag"} ? 1 : 0, "columns", []}
l!l
00
MC/DC0%0/1
$idx_info{$name} //= {"index_name", $name, "table_name", $table, "is_unique", $row->{"rdb\$unique_flag"} ? 1 : 0, "columns", []}
$idx_info{$name}
Truth table0%0/2
A
A= $idx_info{$name}
Aresult
11
00
40 columns => [],
41 };
42  
43 0 my $col = $row->{'rdb$field_name'};
44 0 $col =~ s/\s+$//;
45 0 push @{ $idx_info{$name}{columns} }, $col;
46 }
47  
48 # Filter out PK/UNIQUE-backed indexes by checking rdb$relation_constraints
49 0 my $constr_sth = $dbh->prepare(q{
50 SELECT ix.rdb$index_name
51 FROM rdb$relation_constraints rc
52 JOIN rdb$indices ix ON rc.rdb$index_name = ix.rdb$index_name
53 WHERE rc.rdb$constraint_type IN ('PRIMARY KEY', 'UNIQUE')
54 });
55 0 $constr_sth->execute;
56 0 my %skip_idx;
57 0 ▶ while (my ($idx) = $constr_sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($idx) = $constr_sth->fetchrow_array) 0 0 0
58 0 $idx =~ s/\s+$//;
59 0 $skip_idx{$idx} = 1;
60 }
61  
62 0 for my $name (sort keys %idx_info) {
63 0 ▶ next if $skip_idx{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $skip_idx{$name} 0 0 0
64 0 my $info = $idx_info{$name};
65 $indexes{ $info->{table_name} }{ $name } = {
66 index_name => $name,
67 is_unique => $info->{is_unique},
68 columns => $info->{columns},
69 0 };
70 }
71  
72 0 return \%indexes;
73 }
74  
75 6 1;
76  
77 __END__
↑ Summary Firebird/DDL.pm »