Sybase/Introspect.pm

filter: Statementstmt 44.2% 31 / 70 Branchbran 30.0% 3 / 10 Conditioncond 12.5% 1 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 9 / 12 Podpod 100% 2 / 2 totaltotal 43.4% 46 / 106 CC 14 SCAR 33.0
CC
14
Cov
40%
_mark_pk_index_origin
72.0
_group_fks_by_constraint
20.0
view_definition
3.0
CRAP 27.1
« Sybase/Storage/ASE/LOBWriter.pm ↑ Summary Sybase/Introspect/Tables.pm »
1 package DBIO::Sybase::Introspect;
2 # ABSTRACT: Introspect a Sybase ASE database via information_schema
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 1 ▶use base 'DBIO::Introspect::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 1 ▶use DBIO::Sybase::Introspect::Tables;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use DBIO::Sybase::Introspect::Columns;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use DBIO::Sybase::Introspect::Indexes;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use DBIO::Sybase::Introspect::ForeignKeys;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶sub schema { $_[0]->{schema} // 'dbo' }
Subroutine schema: called CC=2 SCAR=7.6
Pod documented
Condition50%1/2
$_[0]{"schema"} // "dbo"
l!l
02
MC/DC0%0/1
$_[0]{"schema"} // "dbo"
$_[0]{"schema"}
Truth table50%1/2
A
A= $_[0]{"schema"}
Aresult
11
00
16  
17  
18 0 ▶sub _build_model {
Subroutine _build_model: not called CC=1 SCAR=6.9
19 0 my ($self) = @_;
20 0 my $dbh = $self->dbh;
21 0 my $schema = $self->schema;
22  
23 0 my $tables = DBIO::Sybase::Introspect::Tables->fetch($dbh, $schema);
24 0 my $columns = DBIO::Sybase::Introspect::Columns->fetch($dbh, $schema, $tables);
25 0 my $indexes = DBIO::Sybase::Introspect::Indexes->fetch($dbh, $schema, $tables);
26 0 my $fks_raw = DBIO::Sybase::Introspect::ForeignKeys->fetch($dbh, $schema, $tables);
27  
28 # Group the per-column FK rows into one entry per constraint, in declared
29 # order (composite FKs must keep local<->remote column pairing). The
30 # order-preserving grouping lives in DBIO::Introspect::Base.
31 0 my $foreign_keys = $self->_group_fks_by_constraint($fks_raw);
32  
33 # Mark indexes that back a primary key with origin => 'pk' so the inherited
34 # table_uniq_info drops them. PK-backing indexes are matched by column set.
35 0 $self->_mark_pk_index_origin($indexes, $columns);
36  
37 return {
38 0 tables => $tables,
39 columns => $columns,
40 indexes => $indexes,
41 foreign_keys => $foreign_keys,
42 };
43 }
44  
45 0 ▶sub _group_fks_by_constraint {
Subroutine _group_fks_by_constraint: not called CC=4 SCAR=30.0
46 0 my ($self, $fks_raw) = @_;
47 0 my $out = {};
48 0 for my $table (sort keys %$fks_raw) {
49 0 ▶ my $rows = $fks_raw->{$table} // [];
Condition0%0/2
$fks_raw->{$table} // []
l!l
00
MC/DC0%0/1
$fks_raw->{$table} // []
$fks_raw->{$table}
Truth table0%0/2
A
A= $fks_raw->{$table}
Aresult
11
00
50 0 my $ordered = $self->_aggregate_by_ordered($rows, 'constraint_name');
51 0 my @entries;
52 0 for my $pair (@$ordered) {
53 0 my ($cn, $rows) = @$pair;
54 push @entries, {
55 constraint_name => $cn,
56 0 from_columns => [ map { $_->{column_name} } @$rows ],
57 to_table => $rows->[0]{ref_table_name},
58 0 to_columns => [ map { $_->{ref_column_name} } @$rows ],
59 on_update => $rows->[0]{update_rule},
60 on_delete => $rows->[0]{delete_rule},
61 0 };
62 }
63 0 $out->{$table} = \@entries;
64 }
65 0 return $out;
66 }
67  
68 0 ▶sub _mark_pk_index_origin {
Subroutine _mark_pk_index_origin: not called CC=8 SCAR=42.8
69 0 my ($self, $indexes, $columns) = @_;
70 0 for my $table (sort keys %$indexes) {
71 0 ▶ my $tbl_cols = $columns->{$table} // [];
Condition0%0/2
$columns->{$table} // []
l!l
00
MC/DC0%0/1
$columns->{$table} // []
$columns->{$table}
Truth table0%0/2
A
A= $columns->{$table}
Aresult
11
00
72 0 my @pk_cols = sort map { $_->{column_name} }
73 0 grep { $_->{is_pk} } @$tbl_cols;
74 0 ▶ next unless @pk_cols;
Branch: 1 branch
BranchTrueFalseTotal
unless @pk_cols 0 0 0
75 0 my $pk_sig = join "\0", @pk_cols;
76 0 for my $name (sort keys %{ $indexes->{$table} }) {
77 0 my $idx = $indexes->{$table}{$name};
78 0 ▶ my @idx_cols = sort @{ $idx->{columns} // [] };
Condition0%0/2
$idx->{"columns"} // []
l!l
00
MC/DC0%0/1
$idx->{"columns"} // []
$idx->{"columns"}
Truth table0%0/2
A
A= $idx->{"columns"}
Aresult
11
00
79 0 ▶ next unless @idx_cols;
Branch: 1 branch
BranchTrueFalseTotal
unless @idx_cols 0 0 0
80 0 ▶ next unless join("\0", @idx_cols) eq $pk_sig;
Branch: 1 branch
BranchTrueFalseTotal
unless join("\0", @idx_cols) eq $pk_sig 0 0 0
81 0 $idx->{origin} = 'pk';
82 }
83 }
84 }
85  
86  
87 6 ▶sub view_definition {
Subroutine view_definition: called CC=3 SCAR=11.0
Pod documented
88 6 my ($self, $key) = @_;
89 6 ▶ return undef unless $self->table_is_view($key);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->table_is_view($key) 4 2 6
90  
91 2 my ($def) = $self->dbh->selectrow_array(
92 q{SELECT view_definition FROM INFORMATION_SCHEMA.VIEWS
93 WHERE table_schema = ? AND table_name = ?},
94 undef, $self->schema, $key,
95 );
96 2 ▶ return undef unless defined $def;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $def 0 2 2
97 2 $def =~ s/^\s+//;
98 2 $def =~ s/\s+\z//;
99 2 $def =~ s/\s*;\s*\z//;
100 2 return $def;
101 }
102  
103  
104 1 1;
105  
106 __END__
107  
108 =pod
109  
110 =encoding UTF-8
111  
112 =head1 NAME
113  
114 DBIO::Sybase::Introspect - Introspect a Sybase ASE database via information_schema
115  
116 =head1 VERSION
117  
118 version 0.900001
119  
120 =head1 DESCRIPTION
121  
122 C<DBIO::Sybase::Introspect> reads the live state of a Sybase ASE database
123 via the standard SQL C<INFORMATION_SCHEMA> views. It is the source side
124 of the test-deploy-and-compare strategy used by L<DBIO::Sybase::Deploy>.
125  
126 my $intro = DBIO::Sybase::Introspect->new(dbh => $dbh);
127 my $model = $intro->model;
128  
129 Model shape (canonical — single-schema, un-qualified keys):
130  
131 {
132 tables => { $name => { ... } },
133 columns => { $table => [ { ... }, ... ] },
134 indexes => { $table => { $name => { ... } } },
135 foreign_keys => { $table => [ { constraint_name, from_columns,
136 to_table, to_columns,
137 on_update, on_delete } ] },
138 }
139  
140 The FK rows in C<foreign_keys> are pre-grouped per constraint (one entry
141 per FK, with C<from_columns> / C<to_columns> as arrayrefs) so the default
142 L<DBIO::Introspect::Base/table_fk_info> contract method applies unchanged.
143 Each entry also carries C<constraint_name> -- the live, server-assigned
144 name -- so the diff layer can C<DROP>/C<ALTER> a foreign key by its real
145 name instead of a generated one (see ADR 0021; C<constraint_name> is FK
146 metadata, not a compared attribute).
147  
148 =head1 ATTRIBUTES
149  
150 =head2 schema
151  
152 Schema name to introspect. Defaults to C<dbo>.
153  
154 =head1 METHODS
155  
156 =head2 view_definition
157  
158 SQL text of the view definition, or C<undef>.
159  
160 =seealso
161  
162 =over
163  
164 =item * L<DBIO::Sybase::Deploy> - uses this class for test-deploy-and-compare
165  
166 =item * L<DBIO::Sybase::Diff> - compares two models produced by this class
167  
168 =back
169  
170 =head1 AUTHOR
171  
172 DBIO & DBIx::Class Authors
173  
174 =head1 COPYRIGHT AND LICENSE
175  
176 Copyright (C) 2026 DBIO Authors
177 Portions Copyright (C) 2005-2025 DBIx::Class Authors
178 Based on DBIx::Class, heavily modified.
179  
180 This is free software; you can redistribute it and/or modify it under
181 the same terms as the Perl 5 programming language system itself.
182  
183 =cut
« Sybase/Storage/ASE/LOBWriter.pm ↑ Summary Sybase/Introspect/Tables.pm »