| 1 | package DBIO::Informix::Introspect::UniqueConstraints; | ||||||||||
| 2 | # ABSTRACT: Introspect Informix unique constraints | ||||||||||
| 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 | 1 | ▶ | sub fetch { | ||||||||
|
Subroutine
fetch: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||
| 14 | 1 | my ($class, $dbh, $schema, $tables) = @_; | |||||||||
| 15 | 1 | my %out; | |||||||||
| 16 | |||||||||||
| 17 | 1 | local $dbh->{FetchHashKeyName} = 'NAME_lc'; | |||||||||
| 18 | |||||||||||
| 19 | 1 | my $q = DBIO::Informix::Introspect::Util::qualifier($schema); | |||||||||
| 20 | 1 | my $parts = DBIO::Informix::Introspect::Util::_parts_sql(); | |||||||||
| 21 | |||||||||||
| 22 | 1 | for my $table_name (sort grep { $tables->{$_}{kind} eq 'table' } keys %$tables) { | |||||||||
| 23 | 2 | my $sth = $dbh->prepare(qq{ | |||||||||
| 24 | SELECT c.constrname, t.tabid, $parts | ||||||||||
| 25 | FROM $q.sysconstraints c | ||||||||||
| 26 | JOIN $q.systables t ON c.tabid = t.tabid | ||||||||||
| 27 | JOIN $q.sysindexes i ON i.tabid = c.tabid AND i.idxname = c.idxname | ||||||||||
| 28 | WHERE c.constrtype = 'U' | ||||||||||
| 29 | AND t.tabname = ? | ||||||||||
| 30 | ORDER BY c.constrname | ||||||||||
| 31 | }); | ||||||||||
| 32 | 2 | $sth->execute($table_name); | |||||||||
| 33 | 2 | my @rows = @{ $sth->fetchall_arrayref({}) }; | |||||||||
| 34 | 2 | $sth->finish; | |||||||||
| 35 | 2 | ▶ | next unless @rows; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | |||||||||||
| 37 | 0 | my $names = DBIO::Informix::Introspect::Util::column_names($dbh, $q, $rows[0]{tabid}); | |||||||||
| 38 | 0 | for my $row (@rows) { | |||||||||
| 39 | 0 | push @{ $out{$table_name} }, { | |||||||||
| 40 | constraint_name => $row->{constrname}, | ||||||||||
| 41 | 0 | columns => [ DBIO::Informix::Introspect::Util::names_for( | |||||||||
| 42 | $names, DBIO::Informix::Introspect::Util::part_columns($row, 'part')) ], | ||||||||||
| 43 | }; | ||||||||||
| 44 | } | ||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 1 | return \%out; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 21 | 1; | |||||||||
| 51 | |||||||||||
| 52 | __END__ | ||||||||||