Firebird/Introspect/Uniques.pm

filter: Statementstmt 27.5% 8 / 29 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 2 / 4 Podpod 100% 1 / 1 totaltotal 27.5% 11 / 40 CC 5 SCAR 24.6
CC
5
Cov
23%
fetch
20.0
_trim
6.0
BEGIN
1.0
CRAP 11.8
« Firebird/Diff/Table.pm ↑ Summary Firebird/Util.pm »
1 package DBIO::Firebird::Introspect::Uniques;
2 # ABSTRACT: Introspect Firebird UNIQUE constraints via rdb$relation_constraints
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=4 SCAR=30.0
Pod documented
12 0 my ($class, $dbh, $tables) = @_;
13  
14 0 my $sth = $dbh->prepare(q{
15 SELECT rc.rdb$constraint_name, rc.rdb$relation_name,
16 iseg.rdb$field_name, iseg.rdb$field_position
17 FROM rdb$relation_constraints rc
18 JOIN rdb$index_segments iseg ON rc.rdb$index_name = iseg.rdb$index_name
19 WHERE rc.rdb$constraint_type = 'UNIQUE'
20 ORDER BY rc.rdb$relation_name, rc.rdb$constraint_name, iseg.rdb$field_position
21 });
22 0 $sth->execute;
23  
24 0 my %by_table;
25 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
26 0 my $table = _trim($row->{'rdb$relation_name'});
27 0 ▶ next unless exists $tables->{$table};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $tables->{$table} 0 0 0
28  
29 0 my $cname = _trim($row->{'rdb$constraint_name'});
30 0 my $col = _trim($row->{'rdb$field_name'});
31  
32 0 push @{ $by_table{$table}{$cname} }, $col;
33 }
34  
35 0 my %uniques;
36 0 for my $table (keys %by_table) {
37 $uniques{$table} = [
38 0 map { [ $_ => $by_table{$table}{$_} ] }
39 0 sort keys %{ $by_table{$table} }
40 ];
41 }
42  
43 0 return \%uniques;
44 }
45  
46 # Trim trailing whitespace from a CHAR-padded rdb$ value.
47 0 ▶sub _trim {
Subroutine _trim: not called CC=2 SCAR=17.9
48 0 my ($value) = @_;
49 0 ▶ return $value unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
50 0 $value =~ s/\s+$//;
51 0 return $value;
52 }
53  
54 6 1;
55  
56 __END__
« Firebird/Diff/Table.pm ↑ Summary Firebird/Util.pm »