Oracle/Introspect/Views.pm

filter: Statementstmt 100% 37 / 37 Branchbran 93.7% 15 / 16 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 89.5% 60 / 67 CC 12 SCAR 22.9
CC
12
Cov
93%
fetch
12.1
BEGIN
1.0
BEGIN
1.0
CRAP 9.9
« Oracle/Diff/ForeignKey.pm ↑ Summary Oracle/Diff/View.pm »
1 package DBIO::Oracle::Introspect::Views;
2 # ABSTRACT: Introspect the definitions of Oracle views
3  
4 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 27 our $VERSION = '0.900004';
8  
9  
10 27 ▶use constant LONG_READ_LEN => 16 * 1024 * 1024;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 5 ▶sub fetch {
Subroutine fetch: called CC=12 SCAR=24.9
Pod documented
14 5 my ($class, $dbh, $schema, $tables) = @_;
15 5 ▶ $tables //= {};
Condition50%1/2
$tables //= {}
l!l
50
MC/DC0%0/1
$tables //= {}
$tables
Truth table50%1/2
A
A= $tables
Aresult
11
00
16  
17 5 my %views;
18 5 ▶ return \%views unless grep { ( $_->{kind} // '' ) eq 'view' } values %$tables;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {($_->{"kind"} // "") eq "view";} values %$tables 4 1 5
Condition50%1/2
$_->{"kind"} // ""
l!l
70
MC/DC0%0/1
$_->{"kind"} // ""
$_->{"kind"}
Truth table50%1/2
A
A= $_->{"kind"}
Aresult
11
00
19  
20 1 local $dbh->{LongReadLen} = LONG_READ_LEN;
21 1 local $dbh->{LongTruncOk} = 0;
22  
23 1 my $sth = $dbh->prepare(q{
24 SELECT view_name, text
25 FROM all_views
26 WHERE owner = ?
27 ORDER BY view_name
28 });
29 1 $sth->execute($schema);
30  
31 1 ▶ while (my $row = $sth->fetchrow_hashref('NAME_lc')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref("NAME_lc")) 3 1 4
32 3 my $name = $row->{view_name};
33 3 ▶ next unless ( $tables->{$name}{kind} // '' ) eq 'view';
Branch: 1 branch
BranchTrueFalseTotal
unless ($tables->{$name}{"kind"} // "") eq "view" 1 2 3
Condition50%1/2
$tables->{$name}{"kind"} // ""
l!l
30
MC/DC0%0/1
$tables->{$name}{"kind"} // ""
$tables->{$name}{"kind"}
Truth table50%1/2
A
A= $tables->{$name}{"kind"}
Aresult
11
00
34 2 $views{$name} = { view_name => $name, definition => $row->{text}, columns => [], depends_on => [] };
35 }
36  
37 # The names of the columns, in order: the text of a view does not hold the
38 # ones a column list gave (karr k65).
39 1 my $csth = $dbh->prepare(q{
40 SELECT table_name, column_name
41 FROM all_tab_columns
42 WHERE owner = ? AND column_id IS NOT NULL
43 ORDER BY table_name, column_id
44 });
45 1 $csth->execute($schema);
46 1 ▶ while (my $c = $csth->fetchrow_hashref('NAME_lc')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $csth->fetchrow_hashref("NAME_lc")) 4 1 5
47 4 ▶ my $v = $views{ $c->{table_name} } or next;
Branch: 1 branch
BranchTrueFalseTotal
my $v = $views{$c->{"table_name"}} or next 3 1 4
48 3 push @{ $v->{columns} }, $c->{column_name};
49 }
50  
51 # The views a view rests on (karr k65): bare when in this schema, else
52 # owner.view. The diff orders the views by it.
53 1 my $dsth = $dbh->prepare(q{
54 SELECT name, referenced_owner, referenced_name
55 FROM all_dependencies
56 WHERE owner = ? AND type = 'VIEW' AND referenced_type = 'VIEW'
57 ORDER BY name, referenced_owner, referenced_name
58 });
59 1 $dsth->execute($schema);
60 1 ▶ while (my $d = $dsth->fetchrow_hashref('NAME_lc')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $d = $dsth->fetchrow_hashref("NAME_lc")) 2 1 3
61 2 ▶ my $v = $views{ $d->{name} } or next;
Branch: 1 branch
BranchTrueFalseTotal
my $v = $views{$d->{"name"}} or next 2 0 2
62 2 ▶ push @{ $v->{depends_on} },
Branch: 1 branch
BranchTrueFalseTotal
$d->{'referenced_owner'} eq $schema ? : 1 1 2
63 $d->{referenced_owner} eq $schema ? $d->{referenced_name}
64 2 : "$d->{referenced_owner}.$d->{referenced_name}";
65 }
66  
67 1 return \%views;
68 }
69  
70 27 1;
71  
72 __END__
« Oracle/Diff/ForeignKey.pm ↑ Summary Oracle/Diff/View.pm »