Oracle/Introspect/Keys.pm

filter: Statementstmt 71.4% 20 / 28 Branchbran 16.6% 1 / 6 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 3 / 3 Podpod 100% 1 / 1 totaltotal 61.3% 27 / 44 CC 7 SCAR 23.4
CC
7
Cov
61%
fetch
13.1
BEGIN
1.0
BEGIN
1.0
CRAP 10.4
« Oracle/Introspect.pm ↑ Summary Oracle/Diff/ForeignKey.pm »
1 package DBIO::Oracle::Introspect::Keys;
2 # ABSTRACT: Introspect Oracle primary key and unique constraints
3  
4 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 29 our $VERSION = '0.900007';
8  
9  
10  
11 1 ▶sub fetch {
Subroutine fetch: called CC=7 SCAR=25.7
Pod documented
12 1 my ($class, $dbh, $schema, $tables) = @_;
13  
14 1 my %primary;
15 my %unique;
16  
17 1 my $sth = $dbh->prepare_cached(q{
18 SELECT c.constraint_name, c.constraint_type, c.table_name,
19 cc.column_name, cc.position
20 FROM all_constraints c
21 JOIN all_cons_columns cc
22 ON c.constraint_name = cc.constraint_name
23 AND c.owner = cc.owner
24 WHERE c.owner = ?
25 AND c.constraint_type IN ('P', 'U')
26 AND c.table_name NOT LIKE 'BIN$%'
27 ORDER BY NLSSORT(c.table_name, 'NLS_SORT=BINARY'), c.constraint_type,
28 NLSSORT(c.constraint_name, 'NLS_SORT=BINARY'), cc.position
29 });
30 1 $sth->execute($schema);
31  
32 1 my %pk_cols; # table => [cols] in position order
33 my %uniq_cols; # table => { constraint => [cols] }
34  
35 1 ▶ while (my $row = $sth->fetchrow_hashref('NAME_lc')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref("NAME_lc")) 0 1 1
36 0 my $tbl = $row->{table_name};
37 0 ▶ next unless exists $tables->{$tbl};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $tables->{$tbl} 0 0 0
38  
39 0 ▶ if ($row->{constraint_type} eq 'P') {
Branch: 1 branch
BranchTrueFalseTotal
if ($row->{'constraint_type'} eq 'P') { } 0 0 0
40 0 push @{ $pk_cols{$tbl} }, $row->{column_name};
41 }
42 else {
43 0 push @{ $uniq_cols{$tbl}{ $row->{constraint_name} } }, $row->{column_name};
44 }
45 }
46 1 $sth->finish;
47  
48 1 for my $tbl (keys %$tables) {
49 1 ▶ $primary{$tbl} = $pk_cols{$tbl} // [];
Condition50%1/2
$pk_cols{$tbl} // []
l!l
01
MC/DC0%0/1
$pk_cols{$tbl} // []
$pk_cols{$tbl}
Truth table50%1/2
A
A= $pk_cols{$tbl}
Aresult
11
00
50  
51 1 ▶ my $by_name = $uniq_cols{$tbl} // {};
Condition50%1/2
$uniq_cols{$tbl} // {}
l!l
01
MC/DC0%0/1
$uniq_cols{$tbl} // {}
$uniq_cols{$tbl}
Truth table50%1/2
A
A= $uniq_cols{$tbl}
Aresult
11
00
52 0 $unique{$tbl} = [ map { [ $_ => $by_name->{$_} ] } sort keys %$by_name ];
53 }
54  
55 return {
56 1 primary => \%primary,
57 unique => \%unique,
58 };
59 }
60  
61 29 1;
62  
63 __END__
« Oracle/Introspect.pm ↑ Summary Oracle/Diff/ForeignKey.pm »