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 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 29 ▶use constant LONG_READ_LEN => 16 * 1024 * 1024;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 6 ▶sub fetch {
Subroutine fetch: called CC=12 SCAR=24.9
Pod documented
14 6 my ($class, $dbh, $schema, $tables) = @_;
15 6 ▶ $tables //= {};
Condition50%1/2
$tables //= {}
l!l
60
MC/DC0%0/1
$tables //= {}
$tables
Truth table50%1/2
A
A= $tables
Aresult
11
00
16  
17 6 my %views;
18 6 ▶ return \%views unless grep { ( $_->{kind} // '' ) eq 'view' } values %$tables;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {($_->{"kind"} // "") eq "view";} values %$tables 4 2 6
Condition50%1/2
$_->{"kind"} // ""
l!l
80
MC/DC0%0/1
$_->{"kind"} // ""
$_->{"kind"}
Truth table50%1/2
A
A= $_->{"kind"}
Aresult
11
00
19  
20 2 local $dbh->{LongReadLen} = LONG_READ_LEN;
21 2 local $dbh->{LongTruncOk} = 0;
22  
23 2 my $sth = $dbh->prepare(q{
24 SELECT view_name, text
25 FROM all_views
26 WHERE owner = ?
27 ORDER BY NLSSORT(view_name, 'NLS_SORT=BINARY')
28 });
29 2 $sth->execute($schema);
30  
31 2 ▶ while (my $row = $sth->fetchrow_hashref('NAME_lc')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref("NAME_lc")) 3 2 5
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 2 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 NLSSORT(table_name, 'NLS_SORT=BINARY'), column_id
44 });
45 2 $csth->execute($schema);
46 2 ▶ while (my $c = $csth->fetchrow_hashref('NAME_lc')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $csth->fetchrow_hashref("NAME_lc")) 4 2 6
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 2 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 NLSSORT(name, 'NLS_SORT=BINARY'),
58 NLSSORT(referenced_owner, 'NLS_SORT=BINARY'),
59 NLSSORT(referenced_name, 'NLS_SORT=BINARY')
60 });
61 2 $dsth->execute($schema);
62 2 ▶ while (my $d = $dsth->fetchrow_hashref('NAME_lc')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $d = $dsth->fetchrow_hashref("NAME_lc")) 2 2 4
63 2 ▶ my $v = $views{ $d->{name} } or next;
Branch: 1 branch
BranchTrueFalseTotal
my $v = $views{$d->{"name"}} or next 2 0 2
64 2 ▶ push @{ $v->{depends_on} },
Branch: 1 branch
BranchTrueFalseTotal
$d->{'referenced_owner'} eq $schema ? : 1 1 2
65 $d->{referenced_owner} eq $schema ? $d->{referenced_name}
66 2 : "$d->{referenced_owner}.$d->{referenced_name}";
67 }
68  
69 2 return \%views;
70 }
71  
72 29 1;
73  
74 __END__
« Oracle/Diff/ForeignKey.pm ↑ Summary Oracle/Diff/View.pm »