| 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"
MC/DC0%0/1
$schema //= "main"
$schema
Truth table0%0/2
A
A= $schema
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 29 | |||||||||||||
| 30 | 0 | ▶ | while (my $row = $sth->fetchrow_hashref) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 31 | 0 | ▶ | next unless exists $tables->{ $row->{table_name} }; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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__ | ||||||||||||