DB2/Introspect/UniqueConstraints.pm

filter: Statementstmt 100% 24 / 24 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod 100% 1 / 1 totaltotal 97.0% 33 / 34 CC 5 SCAR 13.5
CC
5
Cov
97%
fetch
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.9
« DB2/Storage/DateTimeFormat.pm ↑ Summary DB2/Diff/UniqueConstraint.pm »
1 package DBIO::DB2::Introspect::UniqueConstraints;
2 # ABSTRACT: Introspect DB2 unique constraints
3  
4 37 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 37 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 37 our $VERSION = '0.900007';
8  
9  
10  
11 1 ▶sub fetch {
Subroutine fetch: called CC=5 SCAR=16.1
Pod documented
12 1 my ($class, $dbh, $schema, $tables) = @_;
13 1 local $dbh->{FetchHashKeyName} = 'NAME_lc'; # DBD::DB2 upper-cases hashref keys
14 1 my %ucs = map { $_ => [] } keys %$tables;
15  
16 1 my $sth = $dbh->prepare(q{
17 SELECT tc.tabname, tc.constname, kcu.colname, kcu.colseq
18 FROM syscat.tabconst tc
19 JOIN syscat.keycoluse kcu
20 ON tc.constname = kcu.constname
21 AND tc.tabschema = kcu.tabschema
22 AND tc.tabname = kcu.tabname
23 WHERE tc.tabschema = ?
24 AND tc.type = 'U'
25 ORDER BY tc.tabname, tc.constname, kcu.colseq
26 });
27 1 $sth->execute($schema);
28  
29 1 my (%by_name, @order);
30 1 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 4 1 5
31 4 ▶ next unless exists $tables->{ $row->{tabname} };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$tables{$row->{"tabname"}} 0 4 4
32 4 my $key = join "\0", $row->{tabname}, $row->{constname};
33 4 ▶ push @order, [ $row->{tabname}, $row->{constname} ] unless $by_name{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $by_name{$key} 3 1 4
34 4 push @{ $by_name{$key} }, $row->{colname};
35 }
36 1 push @{ $ucs{ $_->[0] } }, [ $_->[1], $by_name{ join "\0", @$_ } ] for @order;
37  
38 1 return \%ucs;
39 }
40  
41 37 1;
42  
43 __END__
« DB2/Storage/DateTimeFormat.pm ↑ Summary DB2/Diff/UniqueConstraint.pm »