blib/lib/DBIO/DuckDB/Introspect/Uniques.pm

filter: Statementstmt 30.7% 8 / 26 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 66.6% 2 / 3 Podpod 100% 1 / 1 totaltotal 26.8% 11 / 41 CC 6 SCAR 34.6
CC
6
Cov
22%
fetch
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 31.8
« blib/lib/DBIO/DuckDB/Storage.pm ↑ Summary blib/lib/DBIO/DuckDB/Diff/View.pm »
1 package DBIO::DuckDB::Introspect::Uniques;
2 # ABSTRACT: Introspect DuckDB UNIQUE constraints
3  
4 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 10 our $VERSION = '0.900007';
8  
9  
10 0 ▶sub fetch {
Subroutine fetch: not called CC=6 SCAR=37.4
Pod documented
11 0 my ($class, $dbh, $schema, $tables, $catalog) = @_;
12 0 ▶ $schema //= 'main';
Condition0%0/2
$schema //= "main"
l!l
00
MC/DC0%0/1
$schema //= "main"
$schema
Truth table0%0/2
A
A= $schema
Aresult
11
00
13 0 my %uniques;
14  
15 0 my $sql = q{
16 SELECT table_name, constraint_name, constraint_column_names
17 FROM duckdb_constraints()
18 WHERE schema_name = ? AND constraint_type = 'UNIQUE'
19 };
20 0 my @bind = ($schema);
21 0 ▶ if (defined $catalog) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $catalog) 0 0 0
22 0 $sql .= q{ AND database_name = ?};
23 0 push @bind, $catalog;
24 }
25 0 $sql .= q{ ORDER BY table_name, constraint_name};
26  
27 0 my $sth = $dbh->prepare($sql);
28 0 ▶ return \%uniques unless eval { $sth->execute(@bind); 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $sth->execute(@bind); 1 } } 0 0 0
29  
30 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
31 0 ▶ next unless exists $tables->{ $row->{table_name} };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$tables{$row->{"table_name"}} 0 0 0
32 $uniques{ $row->{table_name} }{ $row->{constraint_name} } = {
33 constraint_name => $row->{constraint_name},
34 0 columns => [ @{ $row->{constraint_column_names} } ],
35 };
36 }
37  
38 0 return \%uniques;
39 }
40  
41 10 1;
42  
43 __END__
« blib/lib/DBIO/DuckDB/Storage.pm ↑ Summary blib/lib/DBIO/DuckDB/Diff/View.pm »