DuckDB/Introspect/Tables.pm

filter: Statementstmt 30.4% 7 / 23 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 2 / 3 Podpod 100% 1 / 1 totaltotal 25.6% 10 / 39 CC 6 SCAR 34.6
CC
6
Cov
21%
fetch
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 31.8
« DuckDB/Diff/Table.pm ↑ Summary DuckDB/Storage.pm »
1 package DBIO::DuckDB::Introspect::Tables;
2 # ABSTRACT: Introspect DuckDB tables and views
3  
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8  
9 0 ▶sub fetch {
Subroutine fetch: not called CC=6 SCAR=37.4
Pod documented
10 0 my ($class, $dbh, $schema, $catalog) = @_;
11 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
12  
13 0 my $sql = q{
14 SELECT table_name, table_type
15 FROM information_schema.tables
16 WHERE table_schema = ?
17 AND table_name NOT LIKE 'sqlite_%'
18 };
19 0 my @bind = ($schema);
20  
21 0 ▶ if (defined $catalog) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $catalog) 0 0 0
22 0 $sql .= q{ AND table_catalog = ?};
23 0 push @bind, $catalog;
24 }
25  
26 0 $sql .= q{ ORDER BY table_name};
27  
28 0 my $sth = $dbh->prepare($sql);
29 0 $sth->execute(@bind);
30  
31 0 my %tables;
32 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
33 0 ▶ my $type = lc($row->{table_type} // '');
Condition0%0/2
$row->{"table_type"} // ""
l!l
00
MC/DC0%0/1
$row->{"table_type"} // ""
$row->{"table_type"}
Truth table0%0/2
A
A= $row->{"table_type"}
Aresult
11
00
34 0 ▶ my $kind = $type =~ /view/ ? 'view' : 'table';
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /view/ ? : 0 0 0
35 $tables{ $row->{table_name} } = {
36 table_name => $row->{table_name},
37 0 kind => $kind,
38 schema => $schema,
39 };
40 }
41  
42 0 return \%tables;
43 }
44  
45 5 1;
46  
47 __END__
48  
49 =pod
50  
51 =encoding UTF-8
52  
53 =head1 NAME
54  
55 DBIO::DuckDB::Introspect::Tables - Introspect DuckDB tables and views
56  
57 =head1 VERSION
58  
59 version 0.900001
60  
61 =head1 DESCRIPTION
62  
63 Fetches DuckDB table and view metadata via C<information_schema.tables>.
64 Skips system schemas (C<information_schema>, C<pg_catalog>).
65  
66 =head1 METHODS
67  
68 =head2 fetch
69  
70 my $tables = DBIO::DuckDB::Introspect::Tables->fetch($dbh, $schema);
71 my $tables = DBIO::DuckDB::Introspect::Tables->fetch($dbh, $schema, $catalog);
72  
73 Returns a hashref keyed by table name. Each value has: C<table_name>,
74 C<kind> (C<table> or C<view>), C<schema>.
75  
76 When C<$catalog> is defined an C<AND table_catalog = ?> clause is added.
77  
78 =head1 AUTHOR
79  
80 DBIO Authors
81  
82 =head1 COPYRIGHT AND LICENSE
83  
84 Copyright (C) 2026 DBIO Authors
85  
86 This is free software; you can redistribute it and/or modify it under
87 the same terms as the Perl 5 programming language system itself.
88  
89 =cut
« DuckDB/Diff/Table.pm ↑ Summary DuckDB/Storage.pm »