Sybase/Introspect/Indexes.pm

filter: Statementstmt 43.7% 7 / 16 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 66.6% 2 / 3 Podpod 100% 1 / 1 totaltotal 34.4% 10 / 29 CC 5 SCAR 30.8
CC
5
Cov
29%
fetch
30.0
BEGIN
1.0
BEGIN
1.0
CRAP 21.7
« Sybase/Introspect/Tables.pm ↑ Summary Sybase/Storage/ASE/NoBindVars.pm »
1 package DBIO::Sybase::Introspect::Indexes;
2 # ABSTRACT: Introspect Sybase ASE indexes
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8  
9 0 ▶sub fetch {
Subroutine fetch: not called CC=5 SCAR=34.0
Pod documented
10 0 my ($class, $dbh, $schema, $tables) = @_;
11 0 ▶ $schema //= 'dbo';
Condition0%0/2
$schema //= "dbo"
l!l
00
MC/DC0%0/1
$schema //= "dbo"
$schema
Truth table0%0/2
A
A= $schema
Aresult
11
00
12 0 my %indexes;
13  
14 0 my $sth = $dbh->prepare(q{
15 SELECT i.table_name, i.index_name, i.non_unique,
16 STUFF(
17 (SELECT ', ' + c.column_name
18 FROM INFORMATION_SCHEMA.STATISTICS s2
19 JOIN INFORMATION_SCHEMA.COLUMNS c
20 ON c.table_schema = s2.table_schema
21 AND c.table_name = s2.table_name
22 AND c.column_name = s2.column_name
23 WHERE s2.table_schema = i.table_schema
24 AND s2.table_name = i.table_name
25 AND s2.index_name = i.index_name
26 ORDER BY s2.ordinal_position
27 FOR XML PATH('')), 1, 2, ''
28 ) as index_columns
29 FROM INFORMATION_SCHEMA.STATISTICS i
30 WHERE i.table_schema = ?
31 ORDER BY i.table_name, i.index_name
32 });
33 0 $sth->execute($schema);
34  
35 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
36 0 ▶ next unless exists $tables->{ $row->{table_name} };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$tables{$row->{"table_name"}} 0 0 0
37 $indexes{ $row->{table_name} }{ $row->{index_name} } = {
38 index_name => $row->{index_name},
39 is_unique => ($row->{non_unique} == 0) ? 1 : 0,
40 0 ▶ columns => [ split /, /, $row->{index_columns} ],
Branch: 1 branch
BranchTrueFalseTotal
$row->{'non_unique'} == 0 ? : 0 0 0
41 };
42 }
43  
44 0 return \%indexes;
45 }
46  
47 1 1;
48  
49 __END__
50  
51 =pod
52  
53 =encoding UTF-8
54  
55 =head1 NAME
56  
57 DBIO::Sybase::Introspect::Indexes - Introspect Sybase ASE indexes
58  
59 =head1 VERSION
60  
61 version 0.900001
62  
63 =head1 DESCRIPTION
64  
65 Fetches index metadata via C<INFORMATION_SCHEMA.STATISTICS> and
66 C<INFORMATION_SCHEMA.TABLE_CONSTRAINTS>.
67  
68 =head1 METHODS
69  
70 =head2 fetch
71  
72 my $indexes = DBIO::Sybase::Introspect::Indexes->fetch($dbh, $schema, $tables);
73  
74 Given the tables hashref from L<DBIO::Sybase::Introspect::Tables>,
75 returns a hashref keyed by table name. Each value is a hashref of
76 index hashrefs keyed by index name.
77  
78 =head1 AUTHOR
79  
80 DBIO & DBIx::Class Authors
81  
82 =head1 COPYRIGHT AND LICENSE
83  
84 Copyright (C) 2026 DBIO Authors
85 Portions Copyright (C) 2005-2025 DBIx::Class Authors
86 Based on DBIx::Class, heavily modified.
87  
88 This is free software; you can redistribute it and/or modify it under
89 the same terms as the Perl 5 programming language system itself.
90  
91 =cut
« Sybase/Introspect/Tables.pm ↑ Summary Sybase/Storage/ASE/NoBindVars.pm »