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

filter: Statementstmt 39.2% 11 / 28 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 32.6% 15 / 46 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/Policies.pm ↑ Summary blib/lib/DBIO/PostgreSQL/Introspect.pm »
1 package DBIO::PostgreSQL::Introspect::Sequences;
2 # ABSTRACT: Introspect PostgreSQL sequences
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 s.relname AS sequence_name,
20 d.refobjid::regclass::text AS owned_by_table,
21 t.relname AS owned_by_table_name,
22 a.attname AS owned_by_column,
23 d.deptype = 'i' AS is_identity,
24 seq.seqstart AS start_value,
25 seq.seqincrement AS increment,
26 seq.seqmin AS min_value,
27 seq.seqmax AS max_value,
28 seq.seqcache AS cache_size,
29 seq.seqcycle AS is_cycle,
30 pg_catalog.format_type(seq.seqtypid, NULL) AS data_type
31 FROM pg_catalog.pg_class s
32 JOIN pg_catalog.pg_namespace sn ON sn.oid = s.relnamespace
33 JOIN pg_catalog.pg_sequence seq ON seq.seqrelid = s.oid
34 LEFT JOIN pg_catalog.pg_depend d
35 ON d.classid = 'pg_catalog.pg_class'::pg_catalog.regclass
36 AND d.objid = s.oid
37 AND d.objsubid = 0
38 AND d.refclassid = 'pg_catalog.pg_class'::pg_catalog.regclass
39 AND d.refobjsubid > 0
40 AND d.deptype IN ('a', 'i')
41 LEFT JOIN pg_catalog.pg_class t ON t.oid = d.refobjid
42 LEFT JOIN pg_catalog.pg_attribute a
43 ON a.attrelid = d.refobjid AND a.attnum = d.refobjsubid
44 WHERE s.relkind = 'S'
45 };
46 0 $sql .= DBIO::PostgreSQL::Introspect->system_schema_filter('sn');
47 0 $sql .= DBIO::PostgreSQL::Introspect->extension_member_filter('pg_class', 's.oid');
48 # A sequence that belongs to a column goes where its table goes. For a
49 # sequence of its own d.refobjid is NULL and the condition lets it pass.
50 0 $sql .= DBIO::PostgreSQL::Introspect->extension_member_filter('pg_class', 'd.refobjid');
51  
52 0 my @bind;
53 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
54 0 $sql .= ' AND sn.nspname = ANY($1)';
55 0 push @bind, $filter;
56 }
57  
58 0 $sql .= ' ORDER BY sn.nspname, s.relname';
59  
60 0 my $sth = $dbh->prepare($sql);
61 0 $sth->execute(@bind);
62  
63 0 my %sequences;
64 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
65 0 my $key = DBIO::PostgreSQL::Introspect->qualified_key($row);
66 $sequences{$key} = {
67 schema_name => $row->{schema_name},
68 sequence_name => $row->{sequence_name},
69 owned_by_table => $row->{owned_by_table},
70 owned_by_table_name => $row->{owned_by_table_name},
71 owned_by_column => $row->{owned_by_column},
72 is_identity => $row->{is_identity} ? 1 : 0,
73 start_value => $row->{start_value},
74 increment => $row->{increment},
75 min_value => $row->{min_value},
76 max_value => $row->{max_value},
77 cache_size => $row->{cache_size},
78 is_cycle => $row->{is_cycle} ? 1 : 0,
79 data_type => $row->{data_type},
80 0 ▶ };
Branch: 2 branches
BranchTrueFalseTotal
$row->{'is_identity'} ? : 0 0 0
$row->{'is_cycle'} ? : 0 0 0
81 }
82  
83 0 return \%sequences;
84 }
85  
86 171 1;
87  
88 __END__
« blib/lib/DBIO/PostgreSQL/Introspect/Policies.pm ↑ Summary blib/lib/DBIO/PostgreSQL/Introspect.pm »