| 1 | package DBIO::Sybase::Introspect::Indexes; | ||||||||||||
| 2 | # ABSTRACT: Introspect Sybase ASE indexes | ||||||||||||
| 3 | |||||||||||||
| 4 | 28 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 28 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 28 | our $VERSION = '0.900007'; | |||||||||||
| 8 | |||||||||||||
| 9 | |||||||||||||
| 10 | |||||||||||||
| 11 | 14 | ▶ | sub fetch { | ||||||||||
|
Subroutine
fetch: called CC=9 SCAR=22.1
Pod
documented
| |||||||||||||
| 12 | 14 | my ($class, $dbh, $schema, $tables) = @_; | |||||||||||
| 13 | 14 | ▶ | $schema //= 'dbo'; | ||||||||||
|
Condition50%1/2
$schema //= "dbo"
MC/DC0%0/1
$schema //= "dbo"
$schema
Truth table50%1/2
A
A= $schema
| |||||||||||||
| 14 | 14 | my %indexes; | |||||||||||
| 15 | |||||||||||||
| 16 | my $keys = join ', ', | ||||||||||||
| 17 | 14 | map { "index_col(o.name, i.indid, $_, o.uid) AS k$_" } 1 .. 31; | |||||||||||
| 18 | |||||||||||||
| 19 | 14 | my $rows = $dbh->selectall_arrayref(qq{ | |||||||||||
| 20 | SELECT o.name AS table_name, i.name AS index_name, i.indid, i.status, | ||||||||||||
| 21 | $keys | ||||||||||||
| 22 | FROM sysindexes i | ||||||||||||
| 23 | JOIN sysobjects o ON o.id = i.id | ||||||||||||
| 24 | JOIN sysusers u ON u.uid = o.uid | ||||||||||||
| 25 | WHERE o.type = 'U' | ||||||||||||
| 26 | AND u.name = ? | ||||||||||||
| 27 | AND i.indid BETWEEN 1 AND 250 | ||||||||||||
| 28 | ORDER BY o.name, i.indid | ||||||||||||
| 29 | }, { Slice => {} }, $schema); | ||||||||||||
| 30 | |||||||||||||
| 31 | 14 | for my $row (@$rows) { | |||||||||||
| 32 | 56 | ▶ | next unless exists $tables->{ $row->{table_name} }; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | 56 | my @cols; | |||||||||||
| 34 | 56 | for my $n (1 .. 31) { | |||||||||||
| 35 | 140 | my $col = $row->{"k$n"}; | |||||||||||
| 36 | 140 | ▶ | last unless defined $col; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 37 | 84 | push @cols, $col; | |||||||||||
| 38 | } | ||||||||||||
| 39 | 56 | ▶ | my $status = $row->{status} // 0; | ||||||||||
|
Condition50%1/2
$row->{"status"} // 0
MC/DC0%0/1
$row->{"status"} // 0
$row->{"status"}
Truth table50%1/2
A
A= $row->{"status"}
| |||||||||||||
| 40 | my $idx = { | ||||||||||||
| 41 | index_name => $row->{index_name}, | ||||||||||||
| 42 | 56 | ▶ | is_unique => ($status & 2) ? 1 : 0, | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | columns => \@cols, | ||||||||||||
| 44 | }; | ||||||||||||
| 45 | 56 | ▶ | $idx->{origin} = 'pk' if $status & 2048; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | 56 | $indexes{ $row->{table_name} }{ $row->{index_name} } = $idx; | |||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 14 | return \%indexes; | |||||||||||
| 50 | } | ||||||||||||
| 51 | |||||||||||||
| 52 | 28 | 1; | |||||||||||
| 53 | |||||||||||||
| 54 | __END__ | ||||||||||||