| 1 | package DBIO::DuckDB::Introspect::Tables; | ||||||||||||
| 2 | # ABSTRACT: Introspect DuckDB tables and views | ||||||||||||
| 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 | |||||||||||||
| 11 | 0 | ▶ | sub fetch { | ||||||||||
|
Subroutine
fetch: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||
| 12 | 0 | my ($class, $dbh, $schema, $catalog) = @_; | |||||||||||
| 13 | 0 | ▶ | $schema //= 'main'; | ||||||||||
|
Condition0%0/2
$schema //= "main"
MC/DC0%0/1
$schema //= "main"
$schema
Truth table0%0/2
A
A= $schema
| |||||||||||||
| 14 | |||||||||||||
| 15 | 0 | my $sql = q{ | |||||||||||
| 16 | SELECT t.table_name, t.table_type, v.view_definition | ||||||||||||
| 17 | FROM information_schema.tables t | ||||||||||||
| 18 | LEFT JOIN information_schema.views v | ||||||||||||
| 19 | ON v.table_catalog = t.table_catalog | ||||||||||||
| 20 | AND v.table_schema = t.table_schema | ||||||||||||
| 21 | AND v.table_name = t.table_name | ||||||||||||
| 22 | WHERE t.table_schema = ? | ||||||||||||
| 23 | AND t.table_name NOT LIKE 'sqlite_%' | ||||||||||||
| 24 | }; | ||||||||||||
| 25 | 0 | my @bind = ($schema); | |||||||||||
| 26 | |||||||||||||
| 27 | 0 | ▶ | if (defined $catalog) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | 0 | $sql .= q{ AND t.table_catalog = ?}; | |||||||||||
| 29 | 0 | push @bind, $catalog; | |||||||||||
| 30 | } | ||||||||||||
| 31 | |||||||||||||
| 32 | 0 | $sql .= q{ ORDER BY t.table_name}; | |||||||||||
| 33 | |||||||||||||
| 34 | 0 | my $sth = $dbh->prepare($sql); | |||||||||||
| 35 | 0 | $sth->execute(@bind); | |||||||||||
| 36 | |||||||||||||
| 37 | 0 | my %tables; | |||||||||||
| 38 | 0 | ▶ | while (my $row = $sth->fetchrow_hashref) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 39 | 0 | ▶ | my $type = lc($row->{table_type} // ''); | ||||||||||
|
Condition0%0/2
$row->{"table_type"} // ""
MC/DC0%0/1
$row->{"table_type"} // ""
$row->{"table_type"}
Truth table0%0/2
A
A= $row->{"table_type"}
| |||||||||||||
| 40 | 0 | ▶ | my $kind = $type =~ /view/ ? 'view' : 'table'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | $tables{ $row->{table_name} } = { | ||||||||||||
| 42 | table_name => $row->{table_name}, | ||||||||||||
| 43 | kind => $kind, | ||||||||||||
| 44 | schema => $schema, | ||||||||||||
| 45 | 0 | ▶ | ( $kind eq 'view' ? ( view_definition => $row->{view_definition} ) : () ), | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | }; | ||||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 0 | return \%tables; | |||||||||||
| 50 | } | ||||||||||||
| 51 | |||||||||||||
| 52 | 10 | 1; | |||||||||||
| 53 | |||||||||||||
| 54 | __END__ | ||||||||||||