| 1 | package DBIO::DB2::Introspect::Tables; | ||||||||||||
| 2 | # ABSTRACT: Introspect DB2 tables and views | ||||||||||||
| 3 | |||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | |||||||||||||
| 8 | |||||||||||||
| 9 | 0 | ▶ | sub fetch { | ||||||||||
|
Subroutine
fetch: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 10 | 0 | my ($class, $dbh, $schema) = @_; | |||||||||||
| 11 | 0 | local $dbh->{FetchHashKeyName} = 'NAME_lc'; # DBD::DB2 upper-cases hashref keys | |||||||||||
| 12 | |||||||||||||
| 13 | 0 | my $sth = $dbh->prepare(q{ | |||||||||||
| 14 | SELECT tabname, type, tabschema | ||||||||||||
| 15 | FROM syscat.tables | ||||||||||||
| 16 | WHERE tabschema = ? | ||||||||||||
| 17 | AND tabname NOT LIKE 'EX%' | ||||||||||||
| 18 | ORDER BY tabname | ||||||||||||
| 19 | }); | ||||||||||||
| 20 | 0 | $sth->execute($schema); | |||||||||||
| 21 | |||||||||||||
| 22 | 0 | my %tables; | |||||||||||
| 23 | 0 | ▶ | while (my $row = $sth->fetchrow_hashref) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 24 | # syscat.tables.type is a single char: 'V' = view, 'T' = table, etc. | ||||||||||||
| 25 | 0 | ▶ | my $type = uc($row->{type} // ''); | ||||||||||
|
Condition0%0/2
$row->{"type"} // ""
MC/DC0%0/1
$row->{"type"} // ""
$row->{"type"}
Truth table0%0/2
A
A= $row->{"type"}
| |||||||||||||
| 26 | 0 | ▶ | my $kind = $type eq 'V' ? 'view' : 'table'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | $tables{ $row->{tabname} } = { | ||||||||||||
| 28 | table_name => $row->{tabname}, | ||||||||||||
| 29 | kind => $kind, | ||||||||||||
| 30 | schema => $row->{tabschema}, | ||||||||||||
| 31 | 0 | }; | |||||||||||
| 32 | } | ||||||||||||
| 33 | |||||||||||||
| 34 | 0 | return \%tables; | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | 3 | 1; | |||||||||||
| 38 | |||||||||||||
| 39 | __END__ | ||||||||||||
| 40 | |||||||||||||
| 41 | =pod | ||||||||||||
| 42 | |||||||||||||
| 43 | =encoding UTF-8 | ||||||||||||
| 44 | |||||||||||||
| 45 | =head1 NAME | ||||||||||||
| 46 | |||||||||||||
| 47 | DBIO::DB2::Introspect::Tables - Introspect DB2 tables and views | ||||||||||||
| 48 | |||||||||||||
| 49 | =head1 VERSION | ||||||||||||
| 50 | |||||||||||||
| 51 | version 0.900001 | ||||||||||||
| 52 | |||||||||||||
| 53 | =head1 DESCRIPTION | ||||||||||||
| 54 | |||||||||||||
| 55 | Fetches DB2 table and view metadata via C<SYSCAT.TABLES>. | ||||||||||||
| 56 | |||||||||||||
| 57 | =head1 METHODS | ||||||||||||
| 58 | |||||||||||||
| 59 | =head2 fetch | ||||||||||||
| 60 | |||||||||||||
| 61 | my $tables = DBIO::DB2::Introspect::Tables->fetch($dbh, $schema); | ||||||||||||
| 62 | |||||||||||||
| 63 | Returns a hashref keyed by table name. Each value has: C<table_name>, | ||||||||||||
| 64 | C<kind> (C<table> or C<view>), C<schema>. | ||||||||||||
| 65 | |||||||||||||
| 66 | =head1 AUTHOR | ||||||||||||
| 67 | |||||||||||||
| 68 | DBIO & DBIx::Class Authors | ||||||||||||
| 69 | |||||||||||||
| 70 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 71 | |||||||||||||
| 72 | Copyright (C) 2026 DBIO Authors | ||||||||||||
| 73 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||||||||||||
| 74 | Based on DBIx::Class, heavily modified. | ||||||||||||
| 75 | |||||||||||||
| 76 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 77 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 78 | |||||||||||||
| 79 | =cut | ||||||||||||