| 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 //= {}
MC/DC0%0/1
$tables //= {}
$tables
Truth table50%1/2
A
A= $tables
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 6 | my %views; | |||||||||||||||||||
| 18 | 6 | ▶ | return \%views unless grep { ( $_->{kind} // '' ) eq 'view' } values %$tables; | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$_->{"kind"} // ""
MC/DC0%0/1
$_->{"kind"} // ""
$_->{"kind"}
Truth table50%1/2
A
A= $_->{"kind"}
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 32 | 3 | my $name = $row->{view_name}; | |||||||||||||||||||
| 33 | 3 | ▶ | next unless ( $tables->{$name}{kind} // '' ) eq 'view'; | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$tables->{$name}{"kind"} // ""
MC/DC0%0/1
$tables->{$name}{"kind"} // ""
$tables->{$name}{"kind"}
Truth table50%1/2
A
A= $tables->{$name}{"kind"}
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 47 | 4 | ▶ | my $v = $views{ $c->{table_name} } or next; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 63 | 2 | ▶ | my $v = $views{ $d->{name} } or next; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 2 | ▶ | push @{ $v->{depends_on} }, | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||