| 1 | package DBIO::Informix::Introspect::Tables; | ||||||||||||
| 2 | # ABSTRACT: Introspect Informix tables and views | ||||||||||||
| 3 | |||||||||||||
| 4 | 21 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 21 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 21 | our $VERSION = '0.900007'; | |||||||||||
| 8 | |||||||||||||
| 9 | 21 | ▶ | use DBIO::Informix::Introspect::Util (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | |||||||||||||
| 12 | |||||||||||||
| 13 | 6 | ▶ | sub fetch { | ||||||||||
|
Subroutine
fetch: called CC=10 SCAR=27.5
Pod
documented
| |||||||||||||
| 14 | 6 | my ($class, $dbh, $schema) = @_; | |||||||||||
| 15 | |||||||||||||
| 16 | 6 | my $q = DBIO::Informix::Introspect::Util::qualifier($schema); | |||||||||||
| 17 | |||||||||||||
| 18 | 2 | my $sth = $dbh->prepare(qq{ | |||||||||||
| 19 | SELECT tabname, owner, tabtype | ||||||||||||
| 20 | FROM $q.systables | ||||||||||||
| 21 | WHERE tabtype IN ('T', 'V') | ||||||||||||
| 22 | AND tabid >= 100 | ||||||||||||
| 23 | ORDER BY tabname | ||||||||||||
| 24 | }); | ||||||||||||
| 25 | 2 | $sth->execute; | |||||||||||
| 26 | |||||||||||||
| 27 | 2 | my %tables; | |||||||||||
| 28 | 2 | ▶ | while (my $row = $sth->fetchrow_hashref) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | 3 | ▶ | my $kind = $row->{tabtype} eq 'T' ? 'table' : 'view'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 30 | $tables{ $row->{tabname} } = { | ||||||||||||
| 31 | table_name => $row->{tabname}, | ||||||||||||
| 32 | 3 | ▶ | owner => do { my $o = $row->{owner}; $o =~ s/\s+\z// if defined $o; $o }, | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | kind => $kind, | ||||||||||||
| 34 | }; | ||||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | # The name of each primary key, to drop it with (Informix has no DROP | ||||||||||||
| 38 | # PRIMARY KEY). | ||||||||||||
| 39 | 2 | my $psth = $dbh->prepare(qq{ | |||||||||||
| 40 | SELECT t.tabname, c.constrname | ||||||||||||
| 41 | FROM $q.sysconstraints c JOIN $q.systables t ON t.tabid = c.tabid | ||||||||||||
| 42 | WHERE c.constrtype = 'P' AND t.tabtype = 'T' AND t.tabid >= 100 | ||||||||||||
| 43 | }); | ||||||||||||
| 44 | 2 | $psth->execute; | |||||||||||
| 45 | 2 | ▶ | while (my $row = $psth->fetchrow_hashref) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | 3 | my ($name, $constr) = @{$row}{qw(tabname constrname)}; | |||||||||||
| 47 | 3 | ▶ | $tables{$name}{primary_key_name} = $constr =~ s/\s+\z//r if exists $tables{$name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | # A view carries the text the server keeps for it (sysviews, in chunks of | ||||||||||||
| 51 | # one row each in the order of seqno). The server writes the definition in | ||||||||||||
| 52 | # its own form (owner-qualified, columns listed, padded with blanks), so | ||||||||||||
| 53 | # two definitions are the same when their words are. | ||||||||||||
| 54 | 2 | my @views = grep { $tables{$_}{kind} eq 'view' } keys %tables; | |||||||||||
| 55 | 2 | ▶ | if (@views) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 56 | 0 | my $vsth = $dbh->prepare(qq{ | |||||||||||
| 57 | SELECT t.tabname, v.seqno, v.viewtext | ||||||||||||
| 58 | FROM $q.sysviews v JOIN $q.systables t ON t.tabid = v.tabid | ||||||||||||
| 59 | WHERE t.tabtype = 'V' AND t.tabid >= 100 | ||||||||||||
| 60 | ORDER BY t.tabname, v.seqno | ||||||||||||
| 61 | }); | ||||||||||||
| 62 | 0 | $vsth->execute; | |||||||||||
| 63 | 0 | my %text; | |||||||||||
| 64 | 0 | ▶ | while (my ($name, undef, $chunk) = $vsth->fetchrow_array) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | 0 | $text{$name} .= $chunk; | |||||||||||
| 66 | } | ||||||||||||
| 67 | 0 | for my $name (@views) { | |||||||||||
| 68 | 0 | ▶ | my $def = $text{$name} // ''; | ||||||||||
|
Condition0%0/2
$text{$name} // ""
MC/DC0%0/1
$text{$name} // ""
$text{$name}
Truth table0%0/2
A
A= $text{$name}
| |||||||||||||
| 69 | 0 | $def =~ s/\s+/ /g; | |||||||||||
| 70 | 0 | $def =~ s/\s*;?\s*\z//; | |||||||||||
| 71 | 0 | $tables{$name}{definition} = $def; | |||||||||||
| 72 | } | ||||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | 2 | return \%tables; | |||||||||||
| 76 | } | ||||||||||||
| 77 | |||||||||||||
| 78 | 21 | 1; | |||||||||||
| 79 | |||||||||||||
| 80 | __END__ | ||||||||||||