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

filter: Statementstmt 39.2% 11 / 28 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 30.6% 15 / 49 CC 7 SCAR 36.8
CC
7
Cov
27%
fetch
56.0
BEGIN
1.0
BEGIN
1.0
CRAP 39.5
« blib/lib/DBIO/PostgreSQL/Introspect/Tables.pm ↑ Summary blib/lib/DBIO/PostgreSQL/Introspect/Functions.pm »
1 package DBIO::PostgreSQL::Introspect::Columns;
2 # ABSTRACT: Introspect PostgreSQL table columns
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=7 SCAR=40.3
Pod documented
14 0 my ($class, $dbh, $filter) = @_;
15  
16 0 my $sql = q{
17 SELECT
18 n.nspname AS schema_name,
19 c.relname AS table_name,
20 a.attname AS column_name,
21 a.attnum AS ordinal,
22 pg_catalog.format_type(a.atttypid, a.atttypmod) AS data_type,
23 a.attnotnull AS not_null,
24 pg_catalog.pg_get_expr(d.adbin, d.adrelid) AS default_value,
25 a.attidentity AS identity,
26 a.attgenerated AS generated,
27 a.attislocal AS is_local,
28 col_description(c.oid, a.attnum) AS comment,
29 t.typtype AS type_category,
30 CASE WHEN t.typtype = 'e' THEN t.typname END AS enum_type,
31 CASE WHEN t.typtype = 'c' THEN t.typname END AS composite_type,
32 tn.nspname AS type_schema,
33 CASE WHEN a.attgenerated <> '' THEN (
34 SELECT array_agg(ra.attname::text ORDER BY ra.attname)
35 FROM pg_catalog.pg_depend dd
36 JOIN pg_catalog.pg_attribute ra
37 ON ra.attrelid = dd.refobjid AND ra.attnum = dd.refobjsubid
38 WHERE dd.classid = 'pg_catalog.pg_attrdef'::pg_catalog.regclass
39 AND dd.objid = d.oid
40 AND dd.refclassid = 'pg_catalog.pg_class'::pg_catalog.regclass
41 AND dd.refobjid = a.attrelid
42 AND dd.refobjsubid > 0
43 AND dd.refobjsubid <> a.attnum
44 ) END AS reads_columns
45 FROM pg_catalog.pg_attribute a
46 JOIN pg_catalog.pg_class c ON c.oid = a.attrelid
47 JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
48 JOIN pg_catalog.pg_type t ON t.oid = a.atttypid
49 JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace
50 LEFT JOIN pg_catalog.pg_attrdef d ON d.adrelid = a.attrelid AND d.adnum = a.attnum
51 WHERE a.attnum > 0
52 AND NOT a.attisdropped
53 AND c.relkind IN ('r', 'v', 'm', 'f', 'p')
54 };
55 0 $sql .= DBIO::PostgreSQL::Introspect->system_schema_filter('n');
56 0 $sql .= DBIO::PostgreSQL::Introspect->extension_member_filter('pg_class', 'c.oid');
57  
58 0 my @bind;
59 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
60 0 $sql .= ' AND n.nspname = ANY($1)';
61 0 push @bind, $filter;
62 }
63  
64 0 $sql .= ' ORDER BY n.nspname, c.relname, a.attnum';
65  
66 0 my $sth = $dbh->prepare($sql);
67 0 $sth->execute(@bind);
68  
69 0 my %columns;
70 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
71 0 my $table_key = DBIO::PostgreSQL::Introspect->qualified_key($row);
72 0 ▶ push @{ $columns{$table_key} }, {
Branch: 2 branches
BranchTrueFalseTotal
$row->{'not_null'} ? : 0 0 0
$row->{'is_local'} ? : 0 0 0
Condition0%0/2
$row->{"reads_columns"} // []
l!l
00
MC/DC0%0/1
$row->{"reads_columns"} // []
$row->{"reads_columns"}
Truth table0%0/2
A
A= $row->{"reads_columns"}
Aresult
11
00
73 column_name => $row->{column_name},
74 ordinal => $row->{ordinal},
75 data_type => $row->{data_type},
76 not_null => $row->{not_null} ? 1 : 0,
77 default_value => $row->{default_value},
78 identity => $row->{identity},
79 generated => $row->{generated},
80 is_local => $row->{is_local} ? 1 : 0,
81 comment => $row->{comment},
82 type_category => $row->{type_category},
83 enum_type => $row->{enum_type},
84 composite_type => $row->{composite_type},
85 type_schema => $row->{type_schema},
86 0 depends_on_columns => $row->{reads_columns} // [],
87 };
88 }
89  
90 0 return \%columns;
91 }
92  
93 171 1;
94  
95 __END__
« blib/lib/DBIO/PostgreSQL/Introspect/Tables.pm ↑ Summary blib/lib/DBIO/PostgreSQL/Introspect/Functions.pm »