| 1 | package DBIO::Informix::Introspect; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Introspect an Informix database via its system catalog | ||||||||||||||||||||||||||||
| 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 base 'DBIO::Introspect::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 21 | ▶ | use DBIO::Informix::Introspect::Tables; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 21 | ▶ | use DBIO::Informix::Introspect::Columns; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 21 | ▶ | use DBIO::Informix::Introspect::Indexes; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 21 | ▶ | use DBIO::Informix::Introspect::ForeignKeys; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 21 | ▶ | use DBIO::Informix::Introspect::UniqueConstraints; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 8 | ▶ | sub new { my ($class, %args) = @_; bless \%args, $class } | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 6 | ▶ | sub dbh { $_[0]->{dbh} } | ||||||||||||||||||||||||||
|
Subroutine
dbh: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 7 | ▶ | sub schema { | ||||||||||||||||||||||||||
|
Subroutine
schema: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 23 | 7 | ▶ | $self->{schema} //= do { | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"schema"} //= do {
my($db) = $self->dbh->selectrow_array("SELECT DBINFO('dbname') FROM systables WHERE tabid = 1");
$db =~ s/\s+\z// if defined $db;
$db
}
MC/DC0%0/2
$self->{"schema"} //= do {
my($db) = $self->dbh->selectrow_array("SELECT DBINFO('dbname') FROM systables WHERE tabid = 1");
$db =~ s/\s+\z// if defined $db;
$db
}
$self->{"schema"}
do {
my($db) = $self->dbh->selectrow_array("SELECT DBINFO('dbname') FROM systables WHERE tabid = 1");
$db =~ s/\s+\z// if defined $db;
$db
}
Truth table66%2/3
A //= B
A= $self->{"schema"}B= do {
my($db) = $self->dbh->selectrow_array("SELECT DBINFO('dbname') FROM systables WHERE tabid = 1");
$db =~ s/\s+\z// if defined $db;
$db
}
| |||||||||||||||||||||||||||||
| 24 | 1 | my ($db) = $self->dbh->selectrow_array( | |||||||||||||||||||||||||||
| 25 | q{SELECT DBINFO('dbname') FROM systables WHERE tabid = 1} | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | 1 | ▶ | $db =~ s/\s+\z// if defined $db; # dbinfo pads with blanks | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 1 | $db; | |||||||||||||||||||||||||||
| 29 | }; | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 5 | ▶ | sub _build_model { | ||||||||||||||||||||||||||
|
Subroutine
_build_model: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||
| 35 | 5 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||
| 36 | 5 | my $schema = $self->schema; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 5 | my $tables = DBIO::Informix::Introspect::Tables->fetch($dbh, $schema); | |||||||||||||||||||||||||||
| 39 | 1 | my $columns = DBIO::Informix::Introspect::Columns->fetch($dbh, $schema, $tables); | |||||||||||||||||||||||||||
| 40 | 1 | my $indexes = DBIO::Informix::Introspect::Indexes->fetch($dbh, $schema, $tables); | |||||||||||||||||||||||||||
| 41 | 1 | my $fks = DBIO::Informix::Introspect::ForeignKeys->fetch($dbh, $schema, $tables); | |||||||||||||||||||||||||||
| 42 | 1 | my $uniques = DBIO::Informix::Introspect::UniqueConstraints->fetch($dbh, $schema, $tables); | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | return { | ||||||||||||||||||||||||||||
| 45 | 1 | tables => $tables, | |||||||||||||||||||||||||||
| 46 | columns => $columns, | ||||||||||||||||||||||||||||
| 47 | indexes => $indexes, | ||||||||||||||||||||||||||||
| 48 | foreign_keys => $fks, | ||||||||||||||||||||||||||||
| 49 | unique_constraints => $uniques, | ||||||||||||||||||||||||||||
| 50 | }; | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 5 | ▶ | sub table_columns_info { | ||||||||||||||||||||||||||
|
Subroutine
table_columns_info: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 5 | my ($self, $key) = @_; | |||||||||||||||||||||||||||
| 57 | 5 | my %info; | |||||||||||||||||||||||||||
| 58 | 5 | ▶ | for my $col (@{ $self->model->{columns}{$key} || [] }) { | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->model->{'columns'}{$key} || []
MC/DC0%0/1
$self->model->{'columns'}{$key} || []
$self->model->{'columns'}{$key}
Truth table50%1/2
A
A= $self->model->{'columns'}{$key}
| |||||||||||||||||||||||||||||
| 59 | my %col_info = ( | ||||||||||||||||||||||||||||
| 60 | data_type => $col->{data_type}, | ||||||||||||||||||||||||||||
| 61 | is_nullable => $col->{not_null} ? 0 : 1, | ||||||||||||||||||||||||||||
| 62 | 11 | ▶ | is_auto_increment => $col->{is_auto_increment} ? 1 : 0, | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | 11 | ▶ | $col_info{size} = $col->{size} if defined $col->{size}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 11 | ▶ | $col_info{default_value} = $col->{default_value} if defined $col->{default_value}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 11 | $info{ $col->{column_name} } = \%col_info; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 5 | return \%info; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 8 | ▶ | sub table_uniq_info { | ||||||||||||||||||||||||||
|
Subroutine
table_uniq_info: called CC=10 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 8 | my ($self, $key) = @_; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 8 | my $pk_sig = join "\0", sort @{ $self->table_pk_info($key) }; | |||||||||||||||||||||||||||
| 76 | 8 | ▶ | my $indexes = $self->model->{indexes}{$key} || {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->model->{'indexes'}{$key} || {}
MC/DC100%1/1
$self->model->{'indexes'}{$key} || {}
$self->model->{'indexes'}{$key}
Truth table100%2/2
A
A= $self->model->{'indexes'}{$key}
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 8 | my @uniq; | |||||||||||||||||||||||||||
| 79 | 8 | for my $name (sort keys %$indexes) { | |||||||||||||||||||||||||||
| 80 | 12 | my $idx = $indexes->{$name}; | |||||||||||||||||||||||||||
| 81 | 12 | ▶ | next unless $idx->{unique}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 9 | ▶ | next unless @{ $idx->{columns} || [] }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$idx->{'columns'} || []
MC/DC0%0/1
$idx->{'columns'} || []
$idx->{'columns'}
Truth table50%1/2
A
A= $idx->{'columns'}
| |||||||||||||||||||||||||||||
| 83 | 9 | ▶ | next if length $pk_sig && (join "\0", sort @{ $idx->{columns} }) eq $pk_sig; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $pk_sig and join("\0", sort(@{$idx->{"columns"};})) eq $pk_sig
MC/DC50%1/2
length $pk_sig and join("\0", sort(@{$idx->{"columns"};})) eq $pk_sig
length $pk_sig
join("\0", sort(@{$idx->{"columns"};})) eq $pk_sig
Truth table66%2/3
A and B
A= length $pk_sigB= join("\0", sort(@{$idx->{"columns"};})) eq $pk_sig
| |||||||||||||||||||||||||||||
| 84 | 3 | push @uniq, [ $name => $idx->{columns} ]; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 8 | ▶ | for my $uc (@{ $self->model->{unique_constraints}{$key} || [] }) { | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->model->{'unique_constraints'}{$key} || []
MC/DC0%0/1
$self->model->{'unique_constraints'}{$key} || []
$self->model->{'unique_constraints'}{$key}
Truth table50%1/2
A
A= $self->model->{'unique_constraints'}{$key}
| |||||||||||||||||||||||||||||
| 87 | 0 | push @uniq, [ $uc->{constraint_name} => $uc->{columns} ]; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | 8 | return \@uniq; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 4 | ▶ | sub table_fk_info { | ||||||||||||||||||||||||||
|
Subroutine
table_fk_info: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 4 | my ($self, $key) = @_; | |||||||||||||||||||||||||||
| 95 | 4 | my @fks; | |||||||||||||||||||||||||||
| 96 | 4 | ▶ | for my $fk (@{ $self->model->{foreign_keys}{$key} || [] }) { | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->model->{'foreign_keys'}{$key} || []
MC/DC100%1/1
$self->model->{'foreign_keys'}{$key} || []
$self->model->{'foreign_keys'}{$key}
Truth table100%2/2
A
A= $self->model->{'foreign_keys'}{$key}
| |||||||||||||||||||||||||||||
| 97 | push @fks, { | ||||||||||||||||||||||||||||
| 98 | constraint_name => $fk->{fk_name}, | ||||||||||||||||||||||||||||
| 99 | local_columns => $fk->{from_columns}, | ||||||||||||||||||||||||||||
| 100 | remote_table => $fk->{to_table}, | ||||||||||||||||||||||||||||
| 101 | remote_schema => undef, | ||||||||||||||||||||||||||||
| 102 | remote_columns => $fk->{to_columns}, | ||||||||||||||||||||||||||||
| 103 | attrs => { | ||||||||||||||||||||||||||||
| 104 | on_update => $fk->{upd_rule}, | ||||||||||||||||||||||||||||
| 105 | on_delete => $fk->{del_rule}, | ||||||||||||||||||||||||||||
| 106 | }, | ||||||||||||||||||||||||||||
| 107 | 2 | }; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | 4 | return \@fks; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 21 | 1; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | __END__ | ||||||||||||||||||||||||||||