| 1 | package DBIO::PostgreSQL::Introspect::OutsideReaders; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Introspect the views outside the schema filter that read columns inside it | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 171 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 171 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 171 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 171 | ▶ | use DBIO::PostgreSQL::Introspect (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub fetch { | ||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 0 | my ($class, $dbh, $filter) = @_; | |||||||||||||||||||||||||||
| 15 | 0 | ▶ | return {} unless $filter && @$filter; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$filter and @$filter
MC/DC0%0/2
$filter and @$filter
$filter
@$filter
Truth table0%0/3
A and B
A= $filterB= @$filter
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | my $sql = q{ | |||||||||||||||||||||||||||
| 18 | SELECT DISTINCT | ||||||||||||||||||||||||||||
| 19 | n.nspname AS schema_name, | ||||||||||||||||||||||||||||
| 20 | c.relname AS table_name, | ||||||||||||||||||||||||||||
| 21 | c.relkind AS kind, | ||||||||||||||||||||||||||||
| 22 | rn.nspname AS ref_schema, | ||||||||||||||||||||||||||||
| 23 | r.relname AS ref_name, | ||||||||||||||||||||||||||||
| 24 | a.attname AS ref_column | ||||||||||||||||||||||||||||
| 25 | FROM pg_catalog.pg_rewrite rw | ||||||||||||||||||||||||||||
| 26 | JOIN pg_catalog.pg_class c ON c.oid = rw.ev_class | ||||||||||||||||||||||||||||
| 27 | JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace | ||||||||||||||||||||||||||||
| 28 | JOIN pg_catalog.pg_depend d | ||||||||||||||||||||||||||||
| 29 | ON d.classid = 'pg_catalog.pg_rewrite'::pg_catalog.regclass | ||||||||||||||||||||||||||||
| 30 | AND d.objid = rw.oid | ||||||||||||||||||||||||||||
| 31 | AND d.refclassid = 'pg_catalog.pg_class'::pg_catalog.regclass | ||||||||||||||||||||||||||||
| 32 | AND d.refobjsubid > 0 | ||||||||||||||||||||||||||||
| 33 | JOIN pg_catalog.pg_class r ON r.oid = d.refobjid AND r.oid <> c.oid | ||||||||||||||||||||||||||||
| 34 | JOIN pg_catalog.pg_namespace rn ON rn.oid = r.relnamespace | ||||||||||||||||||||||||||||
| 35 | JOIN pg_catalog.pg_attribute a ON a.attrelid = d.refobjid AND a.attnum = d.refobjsubid | ||||||||||||||||||||||||||||
| 36 | WHERE c.relkind IN ('v', 'm') | ||||||||||||||||||||||||||||
| 37 | AND rn.nspname = ANY($1) | ||||||||||||||||||||||||||||
| 38 | AND NOT (n.nspname = ANY($1)) | ||||||||||||||||||||||||||||
| 39 | }; | ||||||||||||||||||||||||||||
| 40 | 0 | $sql .= DBIO::PostgreSQL::Introspect->system_schema_filter('n'); | |||||||||||||||||||||||||||
| 41 | 0 | $sql .= DBIO::PostgreSQL::Introspect->extension_member_filter('pg_class', 'c.oid'); | |||||||||||||||||||||||||||
| 42 | 0 | $sql .= ' ORDER BY n.nspname, c.relname, rn.nspname, r.relname, a.attname'; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | my $rows = $dbh->selectall_arrayref($sql, { Slice => {} }, $filter); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | my %readers; | |||||||||||||||||||||||||||
| 47 | 0 | for my $row (@$rows) { | |||||||||||||||||||||||||||
| 48 | 0 | my $key = DBIO::PostgreSQL::Introspect->qualified_key($row); | |||||||||||||||||||||||||||
| 49 | 0 | my $read = DBIO::PostgreSQL::Introspect->qualified_key(@{$row}{qw( ref_schema ref_name )}); | |||||||||||||||||||||||||||
| 50 | my $view = $readers{$key} //= { | ||||||||||||||||||||||||||||
| 51 | schema_name => $row->{schema_name}, | ||||||||||||||||||||||||||||
| 52 | table_name => $row->{table_name}, | ||||||||||||||||||||||||||||
| 53 | kind => $row->{kind}, | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | depends_on_columns => {}, | ||||||||||||||||||||||||||
|
Condition0%0/2
$readers{$key} //= {"schema_name", $row->{"schema_name"}, "table_name", $row->{"table_name"}, "kind", $row->{"kind"}, "depends_on_columns", {}}
MC/DC0%0/1
$readers{$key} //= {"schema_name", $row->{"schema_name"}, "table_name", $row->{"table_name"}, "kind", $row->{"kind"}, "depends_on_columns", {}}
$readers{$key}
Truth table0%0/2
A
A= $readers{$key}
| |||||||||||||||||||||||||||||
| 55 | }; | ||||||||||||||||||||||||||||
| 56 | 0 | push @{ $view->{depends_on_columns}{$read} }, $row->{ref_column}; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | return \%readers; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 171 | 1; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | __END__ | ||||||||||||||||||||||||||||