Sybase/Introspect/ForeignKeys.pm

filter: Statementstmt 41.1% 7 / 17 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 66.6% 2 / 3 Podpod 100% 1 / 1 totaltotal 35.7% 10 / 28 CC 4 SCAR 26.1
CC
4
Cov
30%
fetch
20.0
BEGIN
1.0
BEGIN
1.0
CRAP 13.7
« Sybase/Storage/ASE/TxnManager.pm ↑ Summary Sybase/Storage.pm »
1 package DBIO::Sybase::Introspect::ForeignKeys;
2 # ABSTRACT: Introspect Sybase ASE foreign keys
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=4 SCAR=30.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 %foreign_keys;
13  
14 0 my $sth = $dbh->prepare(q{
15 SELECT
16 tc.table_name,
17 tc.constraint_name,
18 kcu.column_name,
19 rc2.table_name AS ref_table_name,
20 kcu2.column_name AS ref_column_name,
21 rc.update_rule,
22 rc.delete_rule
23 FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
24 JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu
25 ON tc.constraint_name = kcu.constraint_name
26 AND tc.table_schema = kcu.table_schema
27 AND tc.table_name = kcu.table_name
28 JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc
29 ON tc.constraint_name = rc.constraint_name
30 AND tc.table_schema = rc.constraint_schema
31 JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu2
32 ON rc.unique_constraint_name = kcu2.constraint_name
33 AND rc.unique_constraint_schema = kcu2.table_schema
34 JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc2
35 ON rc.unique_constraint_name = tc2.constraint_name
36 AND rc.unique_constraint_schema = tc2.table_schema
37 WHERE tc.constraint_type = 'FOREIGN KEY'
38 AND tc.table_schema = ?
39 ORDER BY tc.table_name, tc.constraint_name, kcu.ordinal_position
40 });
41 0 $sth->execute($schema);
42  
43 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
44 0 ▶ next unless exists $tables->{ $row->{table_name} };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$tables{$row->{"table_name"}} 0 0 0
45 0 push @{ $foreign_keys{ $row->{table_name} } }, {
46 constraint_name => $row->{constraint_name},
47 column_name => $row->{column_name},
48 ref_table_name => $row->{ref_table_name},
49 ref_column_name => $row->{ref_column_name},
50 update_rule => $row->{update_rule},
51 delete_rule => $row->{delete_rule},
52 0 };
53 }
54  
55 0 return \%foreign_keys;
56 }
57  
58 1 1;
59  
60 __END__
61  
62 =pod
63  
64 =encoding UTF-8
65  
66 =head1 NAME
67  
68 DBIO::Sybase::Introspect::ForeignKeys - Introspect Sybase ASE foreign keys
69  
70 =head1 VERSION
71  
72 version 0.900001
73  
74 =head1 DESCRIPTION
75  
76 Fetches foreign key metadata via C<INFORMATION_SCHEMA.TABLE_CONSTRAINTS>
77 and C<INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE>.
78  
79 =head1 METHODS
80  
81 =head2 fetch
82  
83 my $fks = DBIO::Sybase::Introspect::ForeignKeys->fetch($dbh, $schema, $tables);
84  
85 Given the tables hashref from L<DBIO::Sybase::Introspect::Tables>,
86 returns a hashref keyed by table name. Each value is an arrayref of
87 foreign key hashrefs.
88  
89 =head1 AUTHOR
90  
91 DBIO & DBIx::Class Authors
92  
93 =head1 COPYRIGHT AND LICENSE
94  
95 Copyright (C) 2026 DBIO Authors
96 Portions Copyright (C) 2005-2025 DBIx::Class Authors
97 Based on DBIx::Class, heavily modified.
98  
99 This is free software; you can redistribute it and/or modify it under
100 the same terms as the Perl 5 programming language system itself.
101  
102 =cut
« Sybase/Storage/ASE/TxnManager.pm ↑ Summary Sybase/Storage.pm »