Informix/Diff/ForeignKey.pm

filter: Statementstmt 99.2% 133 / 134 Branchbran 95.2% 40 / 42 Conditioncond 76.4% 91 / 119 MC/DCmcdc 57.3% 39 / 68 Subroutinesub 100% 22 / 22 Podpod 100% 5 / 5 totaltotal 84.6% 330 / 390 CC 72 SCAR 27.4
CC
72
Cov
89%
diff
35.7
_assert_supported
10.0
_rule
8.0
CRAP 15.4
« Informix/DDL.pm ↑ Summary Informix/Introspect/Tables.pm »
1 package DBIO::Informix::Diff::ForeignKey;
2 # ABSTRACT: Diff operations for Informix foreign keys
3  
4 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 31 our $VERSION = '0.900007';
8  
9 31 ▶use base 'DBIO::Diff::Op';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 31 ▶use DBIO::Informix::Util qw(_quote_ident);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 31 __PACKAGE__->mk_diff_accessors(qw(table_name constraint_name fk_info replaced));
14  
15  
16  
17  
18 109 ▶sub fk_name {
Subroutine fk_name: called CC=4 SCAR=13.9
Pod documented
19 109 my ($table, $fk) = @_;
20 return $fk->{constraint_name} // $fk->{fk_name}
21 109 ▶ // join '_', 'fk', $table, @{ $fk->{from_columns} // [] }, $fk->{to_table};
Condition85%6/7
($fk->{"constraint_name"} // $fk->{"fk_name"}) // join("_", "fk", $table, @{$fk->{"from_columns"} // [];}, $fk->{"to_table"})
l!l
6148
$fk->{"constraint_name"} // $fk->{"fk_name"}
l!l&&r!l&&!r
59248
$fk->{"from_columns"} // []
l!l
480
MC/DC100%2/2
($fk->{"constraint_name"} // $fk->{"fk_name"}) // join("_", "fk", $table, @{$fk->{"from_columns"} // [];}, $fk->{"to_table"})
$fk->{"constraint_name"} $fk->{"fk_name"}
MC/DC0%0/1
$fk->{"from_columns"} // []
$fk->{"from_columns"}
Truth table100%3/3
A // B
A= $fk->{"constraint_name"}B= $fk->{"fk_name"}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $fk->{"from_columns"}
Aresult
11
00
22 }
23  
24 # The name the model gives a key, as DROP CONSTRAINT needs it (the server's
25 # own included).
26 124 ▶sub _real_name {
Subroutine _real_name: called CC=4 SCAR=13.9
27 124 my ($fk) = @_;
28 124 ▶ my $n = $fk->{constraint_name} // $fk->{fk_name};
Condition100%3/3
$fk->{"constraint_name"} // $fk->{"fk_name"}
l!l&&r!l&&!r
72349
MC/DC100%2/2
$fk->{"constraint_name"} // $fk->{"fk_name"}
$fk->{"constraint_name"} $fk->{"fk_name"}
Truth table100%3/3
A // B
A= $fk->{"constraint_name"}B= $fk->{"fk_name"}
ABresult
1X1
011
000
29 124 ▶ return (defined $n && length $n) ? $n : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $n && length $n ? : 75 49 124
Condition66%2/3
defined $n and length $n
!ll&&!rl&&r
49075
MC/DC50%1/2
defined $n and length $n
defined $n length $n
Truth table66%2/3
A and B
A= defined $nB= length $n
ABresult
0X0
100
111
30 }
31  
32 # The name that is written on ADD: one the model states, never one the server
33 # assigned (r<tabid>_<n>).
34 101 ▶sub _explicit_name {
Subroutine _explicit_name: called CC=3 SCAR=11.0
35 101 my ($fk) = @_;
36 101 my $n = _real_name($fk);
37 101 ▶ return undef if !defined $n || $n =~ /\Ar\d+_\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $n or $n =~ /\Ar\d+_\d+\z/ 50 51 101
Condition100%3/3
not defined $n or $n =~ /\Ar\d+_\d+\z/
l!l&&r!l&&!r
48251
MC/DC100%2/2
not defined $n or $n =~ /\Ar\d+_\d+\z/
not defined $n $n =~ /\Ar\d+_\d+\z/
Truth table100%3/3
not(A) or B
A= not defined $nB= $n =~ /\Ar\d+_\d+\z/
ABresult
1X1
011
000
38 51 return $n;
39 }
40  
41 609 ▶sub _rule {
Subroutine _rule: called CC=8 SCAR=20.8
42 609 my ($v) = @_;
43 609 ▶ return '' if !defined $v || $v eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $v or $v eq "" 525 84 609
Condition66%2/3
not defined $v or $v eq ""
l!l&&r!l&&!r
525084
MC/DC50%1/2
not defined $v or $v eq ""
not defined $v $v eq ""
Truth table66%2/3
not(A) or B
A= not defined $vB= $v eq ""
ABresult
1X1
011
000
44 84 $v = uc $v;
45 84 $v =~ s/\s+/ /g;
46 84 ▶ return 'NONE' if $v eq 'R' || $v eq 'RESTRICT' || $v eq 'NO ACTION';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "R" or $v eq "RESTRICT" or $v eq "NO ACTION" 27 57 84
Condition100%6/6
$v eq "R" or $v eq "RESTRICT" or $v eq "NO ACTION"
l!l&&r!l&&!r
21657
$v eq "R" or $v eq "RESTRICT"
l!l&&r!l&&!r
16563
MC/DC100%3/3
$v eq "R" or $v eq "RESTRICT" or $v eq "NO ACTION"
$v eq "R" $v eq "RESTRICT" $v eq "NO ACTION"
Truth table100%4/4
A or B or C
A= $v eq "R"B= $v eq "RESTRICT"C= $v eq "NO ACTION"
ABCresult
1XX1
01X1
0011
0000
47 57 ▶ return 'CASCADE' if $v eq 'CASCADE' || $v eq 'C';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "CASCADE" or $v eq "C" 44 13 57
Condition100%3/3
$v eq "CASCADE" or $v eq "C"
l!l&&r!l&&!r
36813
MC/DC100%2/2
$v eq "CASCADE" or $v eq "C"
$v eq "CASCADE" $v eq "C"
Truth table100%3/3
A or B
A= $v eq "CASCADE"B= $v eq "C"
ABresult
1X1
011
000
48 13 return $v;
49 }
50  
51 # Die unless the key uses only what Informix can express.
52 109 ▶sub _assert_supported {
Subroutine _assert_supported: called CC=10 SCAR=23.1
53 109 my ($table, $fk) = @_;
54 109 my $name = fk_name($table, $fk);
55 109 ▶ my $del = _rule($fk->{on_delete} // $fk->{del_rule});
Condition100%3/3
$fk->{"on_delete"} // $fk->{"del_rule"}
l!l&&r!l&&!r
22384
MC/DC100%2/2
$fk->{"on_delete"} // $fk->{"del_rule"}
$fk->{"on_delete"} $fk->{"del_rule"}
Truth table100%3/3
A // B
A= $fk->{"on_delete"}B= $fk->{"del_rule"}
ABresult
1X1
011
000
56 109 ▶ my $upd = _rule($fk->{on_update} // $fk->{upd_rule});
Condition100%3/3
$fk->{"on_update"} // $fk->{"upd_rule"}
l!l&&r!l&&!r
42103
MC/DC100%2/2
$fk->{"on_update"} // $fk->{"upd_rule"}
$fk->{"on_update"} $fk->{"upd_rule"}
Truth table100%3/3
A // B
A= $fk->{"on_update"}B= $fk->{"upd_rule"}
ABresult
1X1
011
000
57 die sprintf "Informix foreign key %s on table %s: ON DELETE %s is not supported "
58 . "(Informix has only ON DELETE CASCADE); refusing to drop it silently\n",
59 $name, $table, $fk->{on_delete} // $fk->{del_rule}
60 109 ▶ if $del ne '' && $del ne 'NONE' && $del ne 'CASCADE';
Branch: 1 branch
BranchTrueFalseTotal
if $del ne "" and $del ne "NONE" and $del ne "CASCADE" 5 104 109
Condition88%8/9
$del ne "" and $del ne "NONE" and $del ne "CASCADE"
!ll&&!rl&&r
88165
$del ne "" and $del ne "NONE"
!ll&&!rl&&r
84421
$fk->{"on_delete"} // $fk->{"del_rule"}
l!l&&r!l&&!r
410
MC/DC100%3/3
$del ne "" and $del ne "NONE" and $del ne "CASCADE"
$del ne "" $del ne "NONE" $del ne "CASCADE"
MC/DC0%0/2
$fk->{"on_delete"} // $fk->{"del_rule"}
$fk->{"on_delete"} $fk->{"del_rule"}
Truth table100%4/4
A and B and C
A= $del ne ""B= $del ne "NONE"C= $del ne "CASCADE"
ABCresult
0XX0
10X0
1100
1111
Truth table66%2/3
A // B
A= $fk->{"on_delete"}B= $fk->{"del_rule"}
ABresult
1X1
011
000
61 die sprintf "Informix foreign key %s on table %s: ON UPDATE %s is not supported "
62 . "(Informix has no ON UPDATE); refusing to drop it silently\n",
63 $name, $table, $fk->{on_update} // $fk->{upd_rule}
64 104 ▶ if $upd ne '' && $upd ne 'NONE';
Branch: 1 branch
BranchTrueFalseTotal
if $upd ne "" and $upd ne "NONE" 3 101 104
Condition83%5/6
$upd ne "" and $upd ne "NONE"
!ll&&!rl&&r
9833
$fk->{"on_update"} // $fk->{"upd_rule"}
l!l&&r!l&&!r
210
MC/DC100%2/2
$upd ne "" and $upd ne "NONE"
$upd ne "" $upd ne "NONE"
MC/DC0%0/2
$fk->{"on_update"} // $fk->{"upd_rule"}
$fk->{"on_update"} $fk->{"upd_rule"}
Truth table100%3/3
A and B
A= $upd ne ""B= $upd ne "NONE"
ABresult
0X0
100
111
Truth table66%2/3
A // B
A= $fk->{"on_update"}B= $fk->{"upd_rule"}
ABresult
1X1
011
000
65 101 return;
66 }
67  
68 65 ▶sub _cascade {
Subroutine _cascade: called CC=3 SCAR=11.1
69 65 my ($fk) = @_;
70 65 ▶ return _rule($fk->{on_delete} // $fk->{del_rule}) eq 'CASCADE' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
_rule($fk->{'on_delete'} // $fk->{'del_rule'}) eq 'CASCADE' ? : 9 56 65
Condition66%2/3
$fk->{"on_delete"} // $fk->{"del_rule"}
l!l&&r!l&&!r
9056
MC/DC50%1/2
$fk->{"on_delete"} // $fk->{"del_rule"}
$fk->{"on_delete"} $fk->{"del_rule"}
Truth table66%2/3
A // B
A= $fk->{"on_delete"}B= $fk->{"del_rule"}
ABresult
1X1
011
000
71 }
72  
73  
74 65 ▶sub fk_clause {
Subroutine fk_clause: called CC=3 SCAR=11.0
Pod documented
75 65 my ($table, $fk) = @_;
76 65 _assert_supported($table, $fk);
77 65 my $name = _explicit_name($fk);
78 return sprintf 'FOREIGN KEY (%s) REFERENCES %s(%s)%s%s',
79 71 join(', ', map { _quote_ident($_) } @{ $fk->{from_columns} }),
80 _quote_ident($fk->{to_table}),
81 65 ▶ join(', ', map { _quote_ident($_) } @{ $fk->{to_columns} }),
Branch: 2 branches
BranchTrueFalseTotal
_cascade($fk) ? : 9 56 65
defined $name ? : 18 47 65
82 (_cascade($fk) ? ' ON DELETE CASCADE' : ''),
83 (defined $name ? ' CONSTRAINT ' . _quote_ident($name) : '');
84 }
85  
86 # Defaults compare as '', cascade as CASCADE, anything else as itself (so the
87 # change is seen and the add refuses it).
88 326 ▶sub _view_rule {
Subroutine _view_rule: called CC=2 SCAR=6.9
89 326 my ($v) = @_;
90 326 my $r = _rule($v);
91 326 ▶ return $r eq 'NONE' ? '' : $r;
Branch: 1 branch
BranchTrueFalseTotal
$r eq 'NONE' ? : 20 306 326
92 }
93  
94 # Comparison view: Informix knows only cascade or not, and no ON UPDATE.
95 163 ▶sub _view {
Subroutine _view: called CC=3 SCAR=11.0
96 163 my ($fk) = @_;
97 return {
98 from_columns => $fk->{from_columns},
99 to_columns => $fk->{to_columns},
100 to_table => $fk->{to_table},
101 on_delete => _view_rule($fk->{on_delete} // $fk->{del_rule}),
102 163 ▶ on_update => _view_rule($fk->{on_update} // $fk->{upd_rule}),
Condition100%6/6
$fk->{"on_delete"} // $fk->{"del_rule"}
l!l&&r!l&&!r
266131
$fk->{"on_update"} // $fk->{"upd_rule"}
l!l&&r!l&&!r
66151
MC/DC100%2/2
$fk->{"on_delete"} // $fk->{"del_rule"}
$fk->{"on_delete"} $fk->{"del_rule"}
MC/DC100%2/2
$fk->{"on_update"} // $fk->{"upd_rule"}
$fk->{"on_update"} $fk->{"upd_rule"}
Truth table100%3/3
A // B
A= $fk->{"on_delete"}B= $fk->{"del_rule"}
ABresult
1X1
011
000
Truth table100%3/3
A // B
A= $fk->{"on_update"}B= $fk->{"upd_rule"}
ABresult
1X1
011
000
103 };
104 }
105  
106 # Identity of a key: what it says, not what it is called.
107 163 ▶sub _content_key {
Subroutine _content_key: called CC=4 SCAR=14.6
108 163 my ($fk) = @_;
109 163 my $v = _view($fk);
110 163 ▶ return join "\0", join(',', @{ $v->{from_columns} // [] }), $v->{to_table} // '',
Condition50%2/4
$v->{"from_columns"} // []
l!l
1630
$v->{"to_table"} // ""
l!l
1630
MC/DC0%0/1
$v->{"from_columns"} // []
$v->{"from_columns"}
MC/DC0%0/1
$v->{"to_table"} // ""
$v->{"to_table"}
Truth table50%1/2
A
A= $v->{"from_columns"}
Aresult
11
00
Truth table50%1/2
A
A= $v->{"to_table"}
Aresult
11
00
111 163 ▶ join(',', @{ $v->{to_columns} // [] }), $v->{on_delete}, $v->{on_update};
Condition50%1/2
$v->{"to_columns"} // []
l!l
1630
MC/DC0%0/1
$v->{"to_columns"} // []
$v->{"to_columns"}
Truth table50%1/2
A
A= $v->{"to_columns"}
Aresult
11
00
112 }
113  
114 288 ▶sub _keyed {
Subroutine _keyed: called CC=4 SCAR=14.0
115 288 my ($fks) = @_;
116 288 my %out;
117 288 ▶ for my $table (keys %{ $fks // {} }) {
Condition50%1/2
$fks // {}
l!l
2880
MC/DC0%0/1
$fks // {}
$fks
Truth table50%1/2
A
A= $fks
Aresult
11
00
118 149 $out{$table} = [ map { +{ %$_, _content_key => _content_key($_) } }
119 167 ▶ @{ $fks->{$table} // [] } ];
Condition50%1/2
$fks->{$table} // []
l!l
1670
MC/DC0%0/1
$fks->{$table} // []
$fks->{$table}
Truth table50%1/2
A
A= $fks->{$table}
Aresult
11
00
120 }
121 288 return \%out;
122 }
123  
124 44 ▶sub _add {
Subroutine _add: called CC=1 SCAR=0.0
125 44 my ($class, $table, $fk) = @_;
126 44 _assert_supported($table, $fk);
127 36 return $class->new(action => 'add', table_name => $table,
128 constraint_name => _explicit_name($fk), fk_info => $fk);
129 }
130  
131 23 ▶sub _drop {
Subroutine _drop: called CC=1 SCAR=0.0
132 23 my ($class, $table, $fk) = @_;
133 23 return $class->new(action => 'drop', table_name => $table,
134 constraint_name => _real_name($fk), fk_info => $fk);
135 }
136  
137  
138 87 ▶sub diff {
Subroutine diff: called CC=32 SCAR=35.8
Pod documented
139 87 my ($class, $source, $target, $source_tables, $target_tables, $dropped_keys) = @_;
140  
141 my @ops = $class->diff_nested(_keyed($source), _keyed($target),
142 index_by => '_content_key',
143 scope => 'both',
144 source_tables => $source_tables,
145 target_tables => $target_tables,
146 36 ▶ on_new => sub { $class->_add($_[0], $_[2]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
147 20 ▶ on_gone => sub { $class->_drop($_[0], $_[2]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
148 87 );
149 # a changed key is its old form dropped, then the new one added
150 80 @ops = ((grep { $_->action eq 'drop' } @ops), (grep { $_->action ne 'drop' } @ops));
151  
152 # A key that stays but points at a unique constraint dropped here: the
153 # server takes the key along with the constraint (a later DROP CONSTRAINT of
154 # the key is -623), so the key is dropped first and added again after
155 # (karr k27). A key the target no longer has is already an ordinary drop.
156 80 ▶ if ($dropped_keys && %$dropped_keys) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dropped_keys and %$dropped_keys) 17 63 80
Condition100%3/3
$dropped_keys and %$dropped_keys
!ll&&!rl&&r
313217
MC/DC100%2/2
$dropped_keys and %$dropped_keys
$dropped_keys %$dropped_keys
Truth table100%3/3
A and B
A= $dropped_keysB= %$dropped_keys
ABresult
0X0
100
111
157 17 my $want = _keyed($target);
158 17 my %gone = map { $_->table_name . "\0" . _content_key($_->fk_info) => 1 } grep { $_->action eq 'drop' } @ops;
159 17 my (@rebuilt_drop, @rebuilt_add);
160 17 for my $table (sort keys %{ _keyed($source) }) {
161 8 ▶ next if !$source_tables || !exists $source_tables->{$table} || !$target_tables || !exists $target_tables->{$table};
Branch: 1 branch
BranchTrueFalseTotal
unless $source_tables and exists $source_tables->{$table} and $target_tables and exists $target_tables->{$table} 0 8 8
Condition33%3/9
$source_tables and exists $source_tables->{$table} and $target_tables and exists $target_tables->{$table}
!ll&&!rl&&r
008
$source_tables and exists $source_tables->{$table} and $target_tables
!ll&&!rl&&r
008
$source_tables and exists $source_tables->{$table}
!ll&&!rl&&r
008
MC/DC0%0/4
$source_tables and exists $source_tables->{$table} and $target_tables and exists $target_tables->{$table}
$source_tables exists $source_tables->{$table} $target_tables exists $target_tables->{$table}
Truth table20%1/5
A and B and C and D
A= $source_tablesB= exists $source_tables->{$table}C= $target_tablesD= exists $target_tables->{$table}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
162 8 ▶ my %stays = map { $_->{_content_key} => $_ } @{ $want->{$table} // [] };
Condition100%2/2
$want->{$table} // []
l!l
62
MC/DC100%1/1
$want->{$table} // []
$want->{$table}
Truth table100%2/2
A
A= $want->{$table}
Aresult
11
00
163 8 ▶ for my $fk (@{ $source->{$table} // [] }) {
Condition50%1/2
$source->{$table} // []
l!l
80
MC/DC0%0/1
$source->{$table} // []
$source->{$table}
Truth table50%1/2
A
A= $source->{$table}
Aresult
11
00
164 9 my $key = _content_key($fk);
165 9 ▶ next if $gone{"$table\0$key"} || !exists $stays{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $gone{"$table\000$key"} or not exists $stays{$key} 5 4 9
Condition66%2/3
$gone{"$table\000$key"} or not exists $stays{$key}
l!l&&r!l&&!r
504
MC/DC50%1/2
$gone{"$table\000$key"} or not exists $stays{$key}
$gone{"$table\000$key"} not exists $stays{$key}
Truth table66%2/3
A or not(B)
A= $gone{"$table\000$key"}B= not exists $stays{$key}
ABresult
1X1
011
000
166 4 ▶ next unless $dropped_keys->{ join "\0", $fk->{to_table} // '', sort @{ $fk->{to_columns} // [] } };
Branch: 1 branch
BranchTrueFalseTotal
unless $$dropped_keys{join "\0", $fk->{"to_table"} // "", sort(@{$fk->{"to_columns"} // [];})} 1 3 4
Condition50%2/4
$fk->{"to_table"} // ""
l!l
40
$fk->{"to_columns"} // []
l!l
40
MC/DC0%0/1
$fk->{"to_table"} // ""
$fk->{"to_table"}
MC/DC0%0/1
$fk->{"to_columns"} // []
$fk->{"to_columns"}
Truth table50%1/2
A
A= $fk->{"to_table"}
Aresult
11
00
Truth table50%1/2
A
A= $fk->{"to_columns"}
Aresult
11
00
167 3 push @rebuilt_drop, $class->_drop($table, $fk);
168 3 push @rebuilt_add, $class->_add($table, $stays{$key});
169 }
170 }
171 17 push @ops, @rebuilt_drop, @rebuilt_add;
172 17 @ops = ((grep { $_->action eq 'drop' } @ops), (grep { $_->action ne 'drop' } @ops));
173 }
174  
175 # Tables only in the target: their keys are added after the CREATE TABLEs.
176 80 my $keyed = _keyed($target);
177 80 for my $table (sort keys %$keyed) {
178 47 ▶ next if !$target_tables || !exists $target_tables->{$table};
Branch: 1 branch
BranchTrueFalseTotal
unless $target_tables and exists $target_tables->{$table} 0 47 47
Condition33%1/3
$target_tables and exists $target_tables->{$table}
!ll&&!rl&&r
0047
MC/DC0%0/2
$target_tables and exists $target_tables->{$table}
$target_tables exists $target_tables->{$table}
Truth table33%1/3
A and B
A= $target_tablesB= exists $target_tables->{$table}
ABresult
0X0
100
111
179 47 ▶ next if $source_tables && exists $source_tables->{$table};
Branch: 1 branch
BranchTrueFalseTotal
if $source_tables and exists $source_tables->{$table} 42 5 47
Condition66%2/3
$source_tables and exists $source_tables->{$table}
!ll&&!rl&&r
0542
MC/DC50%1/2
$source_tables and exists $source_tables->{$table}
$source_tables exists $source_tables->{$table}
Truth table66%2/3
A and B
A= $source_tablesB= exists $source_tables->{$table}
ABresult
0X0
100
111
180 5 push @ops, map { $class->_add($table, $_) }
181 0 sort { $a->{_content_key} cmp $b->{_content_key} } @{ $keyed->{$table} };
182 }
183  
184 # A drop whose key comes back in this diff is the first half of a change.
185 # "Comes back" is the same table and the same name when the model states
186 # one; the names the server assigns differ from one database to the next, so
187 # a key without a stated name comes back as a key over the same columns.
188 79 my (%back_name, %back_cols);
189 79 for my $op (grep { $_->action eq 'add' } @ops) {
190 36 ▶ $back_name{ join "\0", $op->table_name, $op->constraint_name } = 1 if defined $op->constraint_name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $op->constraint_name 33 3 36
191 36 ▶ $back_cols{ join "\0", $op->table_name, @{ $op->fk_info->{from_columns} // [] } } = 1;
Condition50%1/2
$op->fk_info->{"from_columns"} // []
l!l
360
MC/DC0%0/1
$op->fk_info->{"from_columns"} // []
$op->fk_info->{"from_columns"}
Truth table50%1/2
A
A= $op->fk_info->{"from_columns"}
Aresult
11
00
192 }
193 79 for my $op (grep { $_->action eq 'drop' } @ops) {
194 23 my $name = $op->constraint_name;
195 my $by_name = defined $name && $name !~ /\Ar\d+_\d+\z/
196 23 ▶ && $back_name{ join "\0", $op->table_name, $name };
Condition100%6/6
defined $name && !($name =~ /\Ar\d+_\d+\z/) && $back_name{join "\000", $op->table_name, $name}
!ll&&!rl&&r
3812
defined $name and not $name =~ /\Ar\d+_\d+\z/
!ll&&!rl&&r
1220
MC/DC100%3/3
defined $name && !($name =~ /\Ar\d+_\d+\z/) && $back_name{join "\000", $op->table_name, $name}
defined $name not $name =~ /\Ar\d+_\d+\z/ $back_name{join "\000", $op->table_name, $name}
Truth table100%4/4
A and not(B) && C
A= defined $nameB= not $name =~ /\Ar\d+_\d+\z/C= $back_name{join "\000", $op->table_name, $name}
ABCresult
0XX0
10X0
1100
1111
197 my $by_cols = (!defined $name || $name =~ /\Ar\d+_\d+\z/)
198 23 ▶ && $back_cols{ join "\0", $op->table_name, @{ $op->fk_info->{from_columns} // [] } };
Condition87%7/8
(!defined($name) || $name =~ /\Ar\d+_\d+\z/) && $back_cols{join "\000", $op->table_name, @{$op->fk_info->{'from_columns'} // [];}}
!ll&&!rl&&r
2021
not defined $name or $name =~ /\Ar\d+_\d+\z/
l!l&&r!l&&!r
1220
$op->fk_info->{"from_columns"} // []
l!l
30
MC/DC66%2/3
(!defined($name) || $name =~ /\Ar\d+_\d+\z/) && $back_cols{join "\000", $op->table_name, @{$op->fk_info->{'from_columns'} // [];}}
not defined $name $name =~ /\Ar\d+_\d+\z/ $back_cols{join "\000", $op->table_name, @{$op->fk_info->{'from_columns'} // [];}}
MC/DC0%0/1
$op->fk_info->{"from_columns"} // []
$op->fk_info->{"from_columns"}
Truth table80%4/5
not(A) or B && C
A= not defined $nameB= $name =~ /\Ar\d+_\d+\z/C= $back_cols{join "\000", $op->table_name, @{$op->fk_info->{'from_columns'} // [];}}
ABCresult
00X0
1X00
0100
1X11
0111
Truth table50%1/2
A
A= $op->fk_info->{"from_columns"}
Aresult
11
00
199 23 ▶ $op->replaced(1) if $by_name || $by_cols;
Branch: 1 branch
BranchTrueFalseTotal
if $by_name or $by_cols 13 10 23
Condition100%3/3
$by_name or $by_cols
l!l&&r!l&&!r
12110
MC/DC100%2/2
$by_name or $by_cols
$by_name $by_cols
Truth table100%3/3
A or B
A= $by_nameB= $by_cols
ABresult
1X1
011
000
200 }
201  
202 79 return @ops;
203 }
204  
205  
206 34 ▶sub as_sql {
Subroutine as_sql: called CC=3 SCAR=11.0
Pod documented
207 34 my ($self) = @_;
208 34 my $tbl = _quote_ident($self->table_name);
209  
210 34 ▶ if ($self->action eq 'drop') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->action eq "drop") 14 20 34
211 14 my $name = $self->constraint_name;
212 14 ▶ die sprintf "Informix foreign key on table %s cannot be dropped: the model holds no name for it\n",
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 1 13 14
213 $self->table_name unless defined $name;
214 13 return sprintf 'ALTER TABLE %s DROP CONSTRAINT %s;', $tbl, _quote_ident($name);
215 }
216  
217 20 return sprintf 'ALTER TABLE %s ADD CONSTRAINT %s;', $tbl,
218 fk_clause($self->table_name, $self->fk_info);
219 }
220  
221  
222 5 ▶sub summary {
Subroutine summary: called CC=2 SCAR=8.1
Pod documented
223 5 my ($self) = @_;
224 5 ▶ return sprintf '%s fk: %s on %s', $self->summary_prefix,
Condition33%1/3
$self->constraint_name // fk_name($self->table_name, $self->fk_info)
l!l&&r!l&&!r
500
MC/DC0%0/2
$self->constraint_name // fk_name($self->table_name, $self->fk_info)
$self->constraint_name fk_name($self->table_name, $self->fk_info)
Truth table33%1/3
A // B
A= $self->constraint_nameB= fk_name($self->table_name, $self->fk_info)
ABresult
1X1
011
000
225 $self->constraint_name // fk_name($self->table_name, $self->fk_info),
226 $self->table_name;
227 }
228  
229 31 1;
230  
231 __END__
« Informix/DDL.pm ↑ Summary Informix/Introspect/Tables.pm »