blib/lib/DBIO/PostgreSQL/Introspect/CheckConstraints.pm

filter: Statementstmt 37.9% 11 / 29 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 31.2% 15 / 48 CC 6 SCAR 33.4
CC
6
Cov
28%
fetch
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 28.3
« blib/lib/DBIO/PostgreSQL/Introspect/Types.pm ↑ Summary blib/lib/DBIO/PostgreSQL/Introspect/Policies.pm »
1 package DBIO::PostgreSQL::Introspect::CheckConstraints;
2 # ABSTRACT: Introspect PostgreSQL CHECK constraints
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=6 SCAR=37.4
Pod documented
14 0 my ($class, $dbh, $filter) = @_;
15  
16 0 my $sql = q{
17 SELECT
18 sn.nspname AS schema_name,
19 cl.relname AS table_name,
20 con.conname AS constraint_name,
21 pg_catalog.pg_get_constraintdef(con.oid) AS definition,
22 a.attname AS column_name,
23 k.n AS key_seq
24 FROM pg_catalog.pg_constraint con
25 JOIN pg_catalog.pg_class cl ON cl.oid = con.conrelid
26 JOIN pg_catalog.pg_namespace sn ON sn.oid = cl.relnamespace
27 LEFT JOIN LATERAL unnest(con.conkey) WITH ORDINALITY AS k(attnum, n) ON true
28 LEFT JOIN pg_catalog.pg_attribute a
29 ON a.attrelid = con.conrelid AND a.attnum = k.attnum
30 WHERE con.contype = 'c'
31 AND NOT con.conislocal = false
32 };
33 0 $sql .= DBIO::PostgreSQL::Introspect->system_schema_filter('sn');
34 0 $sql .= DBIO::PostgreSQL::Introspect->extension_member_filter('pg_class', 'cl.oid');
35  
36 0 my @bind;
37 0 ▶ if ($filter && @$filter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filter and @$filter) 0 0 0
Condition0%0/3
$filter and @$filter
!ll&&!rl&&r
000
MC/DC0%0/2
$filter and @$filter
$filter @$filter
Truth table0%0/3
A and B
A= $filterB= @$filter
ABresult
0X0
100
111
38 0 $sql .= ' AND sn.nspname = ANY($1)';
39 0 push @bind, $filter;
40 }
41  
42 0 $sql .= q{
43 ORDER BY sn.nspname, cl.relname, con.conname, k.n
44 };
45  
46 0 my $sth = $dbh->prepare($sql);
47 0 $sth->execute(@bind);
48  
49 0 my %checks;
50 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
51 0 my $table_key = DBIO::PostgreSQL::Introspect->qualified_key($row);
52 my $entry = $checks{$table_key}{ $row->{constraint_name} } //= {
53 constraint_name => $row->{constraint_name},
54 definition => $row->{definition},
55 0 ▶ columns => [],
Condition0%0/2
$checks{$table_key}{$row->{"constraint_name"}} //= {"constraint_name", $row->{"constraint_name"}, "definition", $row->{"definition"}, "columns", []}
l!l
00
MC/DC0%0/1
$checks{$table_key}{$row->{"constraint_name"}} //= {"constraint_name", $row->{"constraint_name"}, "definition", $row->{"definition"}, "columns", []}
$checks{$table_key}{$row->{"constraint_name"}}
Truth table0%0/2
A
A= $checks{$table_key}{$row->{"constraint_name"}}
Aresult
11
00
56 };
57 0 ▶ push @{ $entry->{columns} }, $row->{column_name} if defined $row->{column_name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $row->{"column_name"} 0 0 0
58 }
59  
60 0 return \%checks;
61 }
62  
63 171 1;
64  
65 __END__
« blib/lib/DBIO/PostgreSQL/Introspect/Types.pm ↑ Summary blib/lib/DBIO/PostgreSQL/Introspect/Policies.pm »