DB2/Diff/Column.pm

filter: Statementstmt 98.5% 138 / 140 Branchbran 96.6% 87 / 90 Conditioncond 80.8% 59 / 73 MC/DCmcdc 62.1% 23 / 37 Subroutinesub 100% 18 / 18 Podpod 100% 8 / 8 totaltotal 90.9% 333 / 366 CC 77 SCAR 24.4
CC
77
Cov
94%
as_sql
21.1
diff
18.1
reorg_recommended
9.0
CRAP 11.5
« DB2/Introspect/Columns.pm ↑ Summary DB2/Storage.pm »
1 package DBIO::DB2::Diff::Column;
2 # ABSTRACT: Diff operations for DB2 columns
3  
4 47 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 47 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 47 our $VERSION = '0.900007';
8  
9 47 ▶use base 'DBIO::Diff::Op';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 47 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 47 ▶use DBIO::DB2::Type qw(_db2_column_type);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 47 ▶use DBIO::DB2::DDL qw(_db2_quote_ident _db2_quote_table);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 47 ▶use DBIO::Diff::Compare qw(changed_fields column_change_lossy);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 47 __PACKAGE__->mk_diff_accessors(qw/table_name column_name old_info new_info/);
18  
19  
20 190 ▶sub diff {
Subroutine diff: called CC=18 SCAR=29.0
Pod documented
21 190 my ($class, $source_cols, $target_cols, $source_tables, $target_tables) = @_;
22 190 my @ops;
23  
24 190 for my $table_name (sort keys %$target_cols) {
25 next unless exists $source_tables->{$table_name}
26 224 ▶ && exists $target_tables->{$table_name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $source_tables->{$table_name} and exists $target_tables->{$table_name} 18 206 224
Condition66%2/3
exists $source_tables->{$table_name} and exists $target_tables->{$table_name}
!ll&&!rl&&r
180206
MC/DC50%1/2
exists $source_tables->{$table_name} and exists $target_tables->{$table_name}
exists $source_tables->{$table_name} exists $target_tables->{$table_name}
Truth table66%2/3
A and B
A= exists $source_tables->{$table_name}B= exists $target_tables->{$table_name}
ABresult
0X0
100
111
27  
28 # A view has no columns to ALTER: DBIO::DB2::Diff::View creates and drops
29 # it, and its columns follow its definition (karr k45, ADR 0011). kind may
30 # be marked on either side; a missing kind is 'table'.
31 next if ($target_tables->{$table_name}{kind} // 'table') eq 'view'
32 206 ▶ || ($source_tables->{$table_name}{kind} // 'table') eq 'view';
Branch: 1 branch
BranchTrueFalseTotal
if ($target_tables->{$table_name}{"kind"} // "table") eq "view" or ($source_tables->{$table_name}{"kind"} // "table") eq "view" 16 190 206
Condition85%6/7
($target_tables->{$table_name}{"kind"} // "table") eq "view" or ($source_tables->{$table_name}{"kind"} // "table") eq "view"
l!l&&r!l&&!r
160190
$target_tables->{$table_name}{"kind"} // "table"
l!l
16442
$source_tables->{$table_name}{"kind"} // "table"
l!l
14842
MC/DC50%1/2
($target_tables->{$table_name}{"kind"} // "table") eq "view" or ($source_tables->{$table_name}{"kind"} // "table") eq "view"
$target_tables->{$table_name}{"kind"} $source_tables->{$table_name}{"kind"}
Truth table66%2/3
A or B
A= $target_tables->{$table_name}{"kind"}B= $source_tables->{$table_name}{"kind"}
ABresult
1X1
011
000
33  
34 190 ▶ my %src_by_name = map { $_->{column_name} => $_ } @{ $source_cols->{$table_name} // [] };
Condition50%1/2
$source_cols->{$table_name} // []
l!l
1900
MC/DC0%0/1
$source_cols->{$table_name} // []
$source_cols->{$table_name}
Truth table50%1/2
A
A= $source_cols->{$table_name}
Aresult
11
00
35 190 ▶ my %tgt_by_name = map { $_->{column_name} => $_ } @{ $target_cols->{$table_name} // [] };
Condition50%1/2
$target_cols->{$table_name} // []
l!l
1900
MC/DC0%0/1
$target_cols->{$table_name} // []
$target_cols->{$table_name}
Truth table50%1/2
A
A= $target_cols->{$table_name}
Aresult
11
00
36  
37 190 my @table_ops;
38  
39 190 for my $col_name (sort keys %tgt_by_name) {
40 305 my $tgt = $tgt_by_name{$col_name};
41  
42 305 ▶ if (!exists $src_by_name{$col_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $src_by_name{$col_name}) 53 252 305
43 53 _check_identity($table_name, $col_name, undef, $tgt);
44 49 push @table_ops, $class->new(
45 action => 'add',
46 table_name => $table_name,
47 column_name => $col_name,
48 new_info => $tgt,
49 );
50 49 next;
51 }
52  
53 252 my $src = $src_by_name{$col_name};
54  
55 my $identity_changed = ($src->{is_auto_increment} ? 1 : 0)
56 252 ▶ != ($tgt->{is_auto_increment} ? 1 : 0);
Branch: 2 branches
BranchTrueFalseTotal
$src->{'is_auto_increment'} ? : 12 240 252
$tgt->{'is_auto_increment'} ? : 27 225 252
57  
58 252 ▶ if ($identity_changed || scalar _changed_catalog_fields($src, $tgt)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($identity_changed or scalar _changed_catalog_fields($src, $tgt)) 93 159 252
Condition100%2/2
$identity_changed or scalar _changed_catalog_fields($src, $tgt)
l!l
27225
MC/DC100%1/1
$identity_changed or scalar _changed_catalog_fields($src, $tgt)
$identity_changed
Truth table100%2/2
A
A= $identity_changed
Aresult
11
00
59 93 _check_identity($table_name, $col_name, $src, $tgt);
60 82 push @table_ops, $class->new(
61 action => 'alter',
62 table_name => $table_name,
63 column_name => $col_name,
64 old_info => $src,
65 new_info => $tgt,
66 );
67 }
68 }
69  
70 175 for my $col_name (sort keys %src_by_name) {
71 246 ▶ next if exists $tgt_by_name{$col_name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $tgt_by_name{$col_name} 234 12 246
72 push @table_ops, $class->new(
73 action => 'drop',
74 table_name => $table_name,
75 column_name => $col_name,
76 12 old_info => $src_by_name{$col_name},
77 );
78 }
79  
80 # A table has one identity column (SQL0372N): whatever lets go of its
81 # identity goes first, or the SET GENERATED of another column fails.
82 143 push @ops, (grep { $_->_releases_identity } @table_ops),
83 175 (grep { !$_->_releases_identity } @table_ops);
84 }
85  
86 175 return @ops;
87 }
88  
89 # The comparison core's changed_column_fields, on the catalog fields: the
90 # models hold the normalized column for the generator and the catalog's own
91 # TYPENAME, LENGTH and DEFAULT for this diff (ADR 0013). Same rules as there:
92 # a field the target leaves undef is not compared.
93 225 ▶sub _changed_catalog_fields {
Subroutine _changed_catalog_fields: called CC=6 SCAR=18.3
94 225 my ($old, $new) = @_;
95 225 my @changed = changed_fields($old, $new,
96 type => ['catalog_type'],
97 scalar => ['not_null', 'catalog_default'],
98 dim => ['catalog_size'],
99 );
100 # A default the target no longer declares is a change, as core's
101 # changed_column_fields has it since karr k367: the live column carries one (a
102 # live DEFAULT NULL is none), the target leaves it undef. The pass above skips
103 # a field the target leaves undef, so the removal would never be written
104 # (conformance case diff-default-removed, karr k57). Placed after not_null,
105 # where the scalar pass puts catalog_default.
106 225 ▶ if (!defined $new->{catalog_default} && defined $old->{catalog_default}
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $new->{"catalog_default"} and defined $old->{"catalog_default"} and uc $old->{"catalog_default"} ne "NULL" and not grep({$_ eq "catalog_default";} @changed)) 1 224 225
Condition88%8/9
not defined $new->{"catalog_default"} and defined $old->{"catalog_default"} and uc $old->{"catalog_default"} ne "NULL" and not grep({$_ eq "catalog_default";} @changed)
!ll&&!rl&&r
22401
not defined $new->{"catalog_default"} and defined $old->{"catalog_default"} and uc $old->{"catalog_default"} ne "NULL"
!ll&&!rl&&r
22311
not defined $new->{"catalog_default"} and defined $old->{"catalog_default"}
!ll&&!rl&&r
172062
MC/DC75%3/4
not defined $new->{"catalog_default"} and defined $old->{"catalog_default"} and uc $old->{"catalog_default"} ne "NULL" and not grep({$_ eq "catalog_default";} @changed)
not defined $new->{"catalog_default"} defined $old->{"catalog_default"} uc $old->{"catalog_default"} ne "NULL" not grep({$_ eq "catalog_default";} @changed)
Truth table80%4/5
not(A) and B and C and not(D)
A= not defined $new->{"catalog_default"}B= defined $old->{"catalog_default"}C= uc $old->{"catalog_default"} ne "NULL"D= not grep({$_ eq "catalog_default";} @changed)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
107 && uc($old->{catalog_default}) ne 'NULL'
108 0 && !grep { $_ eq 'catalog_default' } @changed) {
109 0 my ($at) = grep { $changed[$_] eq 'not_null' } 0 .. $#changed;
110 1 ▶ splice @changed, defined $at ? $at + 1 : scalar(@changed), 0, 'catalog_default';
Branch: 1 branch
BranchTrueFalseTotal
defined $at ? : 0 1 1
111 }
112 225 return @changed;
113 }
114  
115  
116 47 my %LOSSLESS_PAIRS = map { ($_ => 1) } (
117 'smallint->integer', 'smallint->bigint', 'integer->bigint',
118 );
119  
120 42 ▶sub lossy {
Subroutine lossy: called CC=3 SCAR=11.0
Pod documented
121 42 my ($self) = @_;
122 42 ▶ return 0 unless $self->action eq 'alter';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->action eq "alter" 22 20 42
123 20 my ($old, $new) = ($self->old_info, $self->new_info);
124 return column_change_lossy(
125 { data_type => $old->{catalog_type}, size => $old->{catalog_size} },
126 { data_type => $new->{catalog_type}, size => $new->{catalog_size} },
127 20 ▶ \%LOSSLESS_PAIRS,
Branch: 1 branch
BranchTrueFalseTotal
column_change_lossy({'data_type', $old->{'catalog_type'}, 'size', $old->{'catalog_size'}}, {'data_type', $new->{'catalog_type'}, 'size', $new->{'catalog_size'}}, \%LOSSLESS_PAIRS) ? : 6 14 20
128 ) ? 1 : 0;
129 }
130  
131  
132 29 ▶sub adds_identity {
Subroutine adds_identity: called CC=3 SCAR=11.0
Pod documented
133 29 my ($self) = @_;
134 29 ▶ return ($self->action eq 'add' && $self->new_info->{is_auto_increment}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->action eq 'add' && $self->new_info->{'is_auto_increment'} ? : 14 15 29
Condition100%3/3
$self->action eq "add" and $self->new_info->{"is_auto_increment"}
!ll&&!rl&&r
6914
MC/DC100%2/2
$self->action eq "add" and $self->new_info->{"is_auto_increment"}
$self->action eq "add" $self->new_info->{"is_auto_increment"}
Truth table100%3/3
A and B
A= $self->action eq "add"B= $self->new_info->{"is_auto_increment"}
ABresult
0X0
100
111
135 }
136  
137  
138 20 ▶sub adds_not_null_without_default {
Subroutine adds_not_null_without_default: called CC=6 SCAR=17.9
Pod documented
139 20 my ($self) = @_;
140 20 ▶ return 0 unless $self->action eq 'add';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->action eq "add" 6 14 20
141 14 my $info = $self->new_info;
142 14 ▶ return 0 if $info->{is_auto_increment} || !$info->{not_null};
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"is_auto_increment"} or not $info->{"not_null"} 7 7 14
Condition100%3/3
$info->{"is_auto_increment"} or not $info->{"not_null"}
l!l&&r!l&&!r
617
MC/DC100%2/2
$info->{"is_auto_increment"} or not $info->{"not_null"}
$info->{"is_auto_increment"} not $info->{"not_null"}
Truth table100%3/3
A or not(B)
A= $info->{"is_auto_increment"}B= not $info->{"not_null"}
ABresult
1X1
011
000
143 7 my $default = $info->{catalog_default};
144 7 ▶ return (defined $default && uc($default) ne 'NULL') ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $default && uc $default ne 'NULL' ? : 4 3 7
Condition100%3/3
defined $default and uc $default ne "NULL"
!ll&&!rl&&r
214
MC/DC100%2/2
defined $default and uc $default ne "NULL"
defined $default uc $default ne "NULL"
Truth table100%3/3
A and B
A= defined $defaultB= uc $default ne "NULL"
ABresult
0X0
100
111
145 }
146  
147  
148 17 ▶sub sets_not_null {
Subroutine sets_not_null: called CC=6 SCAR=18.5
Pod documented
149 17 my ($self) = @_;
150 return ($self->action eq 'alter'
151 17 ▶ && !($self->old_info->{not_null} // 0) && ($self->new_info->{not_null} // 0)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->action eq 'alter' && !($self->old_info->{'not_null'} // 0) && ($self->new_info->{'not_null'} // 0) ? : 4 13 17
Condition70%7/10
$self->action eq "alter" and not $self->old_info->{"not_null"} // 0 and $self->new_info->{"not_null"} // 0
!ll&&!rl&&r
1304
$self->action eq "alter" and not $self->old_info->{"not_null"} // 0
!ll&&!rl&&r
1124
$self->old_info->{"not_null"} // 0
l!l
60
$self->new_info->{"not_null"} // 0
l!l
40
MC/DC0%0/3
$self->action eq "alter" and not $self->old_info->{"not_null"} // 0 and $self->new_info->{"not_null"} // 0
$self->action eq "alter" $self->old_info->{"not_null"} $self->new_info->{"not_null"}
Truth table50%2/4
A and not(B) and C
A= $self->action eq "alter"B= $self->old_info->{"not_null"}C= $self->new_info->{"not_null"}
ABCresult
0XX0
11X0
1000
1011
152 }
153  
154 286 ▶sub _releases_identity {
Subroutine _releases_identity: called CC=5 SCAR=16.1
155 286 my ($self) = @_;
156 286 ▶ my $old = $self->old_info or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $old = $self->old_info or return 0 188 98 286
157 188 ▶ return 0 unless $old->{is_auto_increment};
Branch: 1 branch
BranchTrueFalseTotal
unless $old->{"is_auto_increment"} 174 14 188
158 14 ▶ return 1 if $self->action eq 'drop';
Branch: 1 branch
BranchTrueFalseTotal
if $self->action eq "drop" 2 12 14
159 12 ▶ return $self->new_info->{is_auto_increment} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->new_info->{'is_auto_increment'} ? : 0 12 12
160 }
161  
162 # The identity cases the server refuses (ADR 0012), refused here with table and
163 # column named instead of SQL0846N / SQL0270N from the middle of an upgrade.
164 # $old is undef for an added column. Nothing to check when the column is no
165 # identity afterwards.
166 146 ▶sub _check_identity {
Subroutine _check_identity: called CC=8 SCAR=20.8
167 146 my ($table, $column, $old, $new) = @_;
168 146 ▶ return unless $new->{is_auto_increment};
Branch: 1 branch
BranchTrueFalseTotal
unless $new->{"is_auto_increment"} 102 44 146
169  
170 44 my $where = "table $table, column $column";
171 44 my $type = _db2_column_type($new->{catalog_type}, $new->{catalog_size}, $column);
172  
173 44 ▶ Carp::croak("Cannot make an identity column ($where): Db2 takes an identity only over "
Branch: 1 branch
BranchTrueFalseTotal
unless $type =~ /\A(?:SMALLINT|INTEGER|BIGINT)\z/ or $type =~ /\A(?:DECIMAL|NUMERIC)(?:\(\s*\d+\s*(?:,\s*0\s*)?\))?\z/ 12 32 44
Condition100%3/3
$type =~ /\A(?:SMALLINT|INTEGER|BIGINT)\z/ or $type =~ /\A(?:DECIMAL|NUMERIC)(?:\(\s*\d+\s*(?:,\s*0\s*)?\))?\z/
l!l&&r!l&&!r
30212
MC/DC100%2/2
$type =~ /\A(?:SMALLINT|INTEGER|BIGINT)\z/ or $type =~ /\A(?:DECIMAL|NUMERIC)(?:\(\s*\d+\s*(?:,\s*0\s*)?\))?\z/
$type =~ /\A(?:SMALLINT|INTEGER|BIGINT)\z/ $type =~ /\A(?:DECIMAL|NUMERIC)(?:\(\s*\d+\s*(?:,\s*0\s*)?\))?\z/
Truth table100%3/3
A or B
A= $type =~ /\A(?:SMALLINT|INTEGER|BIGINT)\z/B= $type =~ /\A(?:DECIMAL|NUMERIC)(?:\(\s*\d+\s*(?:,\s*0\s*)?\))?\z/
ABresult
1X1
011
000
174 . "SMALLINT, INTEGER, BIGINT or a DECIMAL without scale, not $type")
175 unless $type =~ /\A(?:SMALLINT|INTEGER|BIGINT)\z/
176 || $type =~ /\A(?:DECIMAL|NUMERIC)(?:\(\s*\d+\s*(?:,\s*0\s*)?\))?\z/;
177  
178 Carp::croak("Cannot make an identity column ($where): an identity column must be NOT NULL")
179 32 ▶ unless $new->{not_null};
Branch: 1 branch
BranchTrueFalseTotal
unless $new->{"not_null"} 1 31 32
180  
181 31 ▶ if ($old && $old->{is_auto_increment}
Branch: 1 branch
BranchTrueFalseTotal
if ($old and $old->{"is_auto_increment"} and $type ne _db2_column_type($old->{"catalog_type"}, $old->{"catalog_size"}, $column)) 2 29 31
Condition83%5/6
$old and $old->{"is_auto_increment"} and $type ne _db2_column_type($old->{"catalog_type"}, $old->{"catalog_size"}, $column)
!ll&&!rl&&r
2902
$old and $old->{"is_auto_increment"}
!ll&&!rl&&r
17122
MC/DC66%2/3
$old and $old->{"is_auto_increment"} and $type ne _db2_column_type($old->{"catalog_type"}, $old->{"catalog_size"}, $column)
$old $old->{"is_auto_increment"} $type ne _db2_column_type($old->{"catalog_type"}, $old->{"catalog_size"}, $column)
Truth table75%3/4
A and B and C
A= $oldB= $old->{"is_auto_increment"}C= $type ne _db2_column_type($old->{"catalog_type"}, $old->{"catalog_size"}, $column)
ABCresult
0XX0
10X0
1100
1111
182 && $type ne _db2_column_type($old->{catalog_type}, $old->{catalog_size}, $column)) {
183 2 Carp::croak("Cannot change the type of an identity column ($where) to $type: "
184 . "Db2 refuses SET DATA TYPE on an identity column (SQL0270N)");
185 }
186 29 return;
187 }
188  
189  
190 81 ▶sub as_sql {
Subroutine as_sql: called CC=21 SCAR=30.5
Pod documented
191 81 my ($self) = @_;
192  
193 81 my $tbl = _db2_quote_table($self->table_name);
194 81 my $col = _db2_quote_ident($self->column_name);
195  
196 81 ▶ if ($self->action eq 'add') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->action eq "add") 39 42 81
197 39 my $info = $self->new_info;
198 39 my $type = _db2_column_type($info->{catalog_type}, $info->{catalog_size}, $self->column_name);
199 39 my $sql = sprintf 'ALTER TABLE %s ADD COLUMN %s %s', $tbl, $col, $type;
200 39 ▶ $sql .= ' NOT NULL' if $info->{not_null};
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"not_null"} 18 21 39
201 39 ▶ if ($info->{is_auto_increment}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"is_auto_increment"}) 10 29 39
202 # The only form the server takes (ADR 0012); existing rows stay at 0.
203 10 return join "\n",
204 "$sql DEFAULT 0;",
205 sprintf('ALTER TABLE %s ALTER COLUMN %s DROP DEFAULT;', $tbl, $col),
206 sprintf('ALTER TABLE %s ALTER COLUMN %s SET GENERATED ALWAYS AS IDENTITY;', $tbl, $col);
207 }
208 29 ▶ if (defined $info->{catalog_default}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"catalog_default"}) 16 13 29
209 # As it is -- the catalog's DEFAULT is SQL text already (see DESCRIPTION).
210 16 $sql .= ' DEFAULT ' . $info->{catalog_default};
211 }
212 29 return "$sql;";
213 }
214  
215 42 ▶ if ($self->action eq 'drop') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->action eq "drop") 8 34 42
216 8 return sprintf 'ALTER TABLE %s DROP COLUMN %s;', $tbl, $col;
217 }
218  
219 34 ▶ if ($self->action eq 'alter') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->action eq "alter") 34 0 34
220 34 my $old = $self->old_info;
221 34 my $new = $self->new_info;
222 34 my @stmts;
223  
224 # An identity is let go of before anything else, and taken after the
225 # NOT NULL and the missing default it needs (ADR 0012).
226 push @stmts, sprintf 'ALTER TABLE %s ALTER COLUMN %s DROP IDENTITY;', $tbl, $col
227 34 ▶ if $old->{is_auto_increment} && !$new->{is_auto_increment};
Branch: 1 branch
BranchTrueFalseTotal
if $old->{"is_auto_increment"} and not $new->{"is_auto_increment"} 4 30 34
Condition66%2/3
$old->{"is_auto_increment"} and not $new->{"is_auto_increment"}
!ll&&!rl&&r
3004
MC/DC50%1/2
$old->{"is_auto_increment"} and not $new->{"is_auto_increment"}
$old->{"is_auto_increment"} not $new->{"is_auto_increment"}
Truth table66%2/3
A and not(B)
A= $old->{"is_auto_increment"}B= not $new->{"is_auto_increment"}
ABresult
0X0
100
111
228  
229 34 ▶ if (_db2_column_type($old->{catalog_type}, $old->{catalog_size})
Branch: 1 branch
BranchTrueFalseTotal
if (_db2_column_type($old->{"catalog_type"}, $old->{"catalog_size"}) ne _db2_column_type($new->{"catalog_type"}, $new->{"catalog_size"})) 8 26 34
230 ne _db2_column_type($new->{catalog_type}, $new->{catalog_size})) {
231 push @stmts, sprintf 'ALTER TABLE %s ALTER COLUMN %s SET DATA TYPE %s;',
232 8 $tbl, $col, _db2_column_type($new->{catalog_type}, $new->{catalog_size});
233 }
234 34 ▶ if (($old->{not_null} // 0) != ($new->{not_null} // 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (($old->{"not_null"} // 0) != ($new->{"not_null"} // 0)) 9 25 34
Condition100%4/4
$old->{"not_null"} // 0
l!l
322
$new->{"not_null"} // 0
l!l
322
MC/DC100%1/1
$old->{"not_null"} // 0
$old->{"not_null"}
MC/DC100%1/1
$new->{"not_null"} // 0
$new->{"not_null"}
Truth table100%2/2
A
A= $old->{"not_null"}
Aresult
11
00
Truth table100%2/2
A
A= $new->{"not_null"}
Aresult
11
00
235 push @stmts, $new->{not_null}
236 9 ▶ ? sprintf('ALTER TABLE %s ALTER COLUMN %s SET NOT NULL;', $tbl, $col)
Branch: 1 branch
BranchTrueFalseTotal
$new->{'not_null'} ? : 6 3 9
237 : sprintf('ALTER TABLE %s ALTER COLUMN %s DROP NOT NULL;', $tbl, $col);
238 }
239 34 ▶ my $old_d = defined $old->{catalog_default} ? $old->{catalog_default} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $old->{'catalog_default'} ? : 15 19 34
240 my $new_d = defined $new->{catalog_default} && !$new->{is_auto_increment}
241 34 ▶ ? $new->{catalog_default} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $new->{'catalog_default'} && !$new->{'is_auto_increment'} ? : 13 21 34
Condition66%2/3
defined $new->{"catalog_default"} and not $new->{"is_auto_increment"}
!ll&&!rl&&r
21013
MC/DC50%1/2
defined $new->{"catalog_default"} and not $new->{"is_auto_increment"}
defined $new->{"catalog_default"} not $new->{"is_auto_increment"}
Truth table66%2/3
A and not(B)
A= defined $new->{"catalog_default"}B= not $new->{"is_auto_increment"}
ABresult
0X0
100
111
242 34 ▶ if ($old_d ne $new_d) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_d ne $new_d) 16 18 34
243 16 ▶ push @stmts, length $new_d
Branch: 1 branch
BranchTrueFalseTotal
length $new_d ? : 13 3 16
244 ? sprintf('ALTER TABLE %s ALTER COLUMN %s SET DEFAULT %s;', $tbl, $col,
245 $new_d)
246 : sprintf('ALTER TABLE %s ALTER COLUMN %s DROP DEFAULT;', $tbl, $col);
247 }
248 push @stmts, sprintf 'ALTER TABLE %s ALTER COLUMN %s SET GENERATED ALWAYS AS IDENTITY;', $tbl, $col
249 34 ▶ if $new->{is_auto_increment} && !$old->{is_auto_increment};
Branch: 1 branch
BranchTrueFalseTotal
if $new->{"is_auto_increment"} and not $old->{"is_auto_increment"} 6 28 34
Condition66%2/3
$new->{"is_auto_increment"} and not $old->{"is_auto_increment"}
!ll&&!rl&&r
2806
MC/DC50%1/2
$new->{"is_auto_increment"} and not $old->{"is_auto_increment"}
$new->{"is_auto_increment"} not $old->{"is_auto_increment"}
Truth table66%2/3
A and not(B)
A= $new->{"is_auto_increment"}B= not $old->{"is_auto_increment"}
ABresult
0X0
100
111
250 34 return join "\n", @stmts;
251 }
252 }
253  
254  
255 # The types within which SET DATA TYPE to another length is not
256 # reorg-recommended, by the name _db2_column_type renders -- which is the
257 # catalog's TYPENAME for all three.
258 47 my %LENGTH_CHANGE_WITHOUT_REORG = map { $_ => 1 } qw(VARCHAR VARGRAPHIC VARBINARY);
259  
260 140 ▶sub reorg_recommended {
Subroutine reorg_recommended: called CC=9 SCAR=22.0
Pod documented
261 140 my ($self) = @_;
262  
263 140 ▶ return 1 if $self->action eq 'drop';
Branch: 1 branch
BranchTrueFalseTotal
if $self->action eq "drop" 12 128 140
264 128 ▶ return 0 unless $self->action eq 'alter';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->action eq "alter" 34 94 128
265  
266 94 my $old = $self->old_info;
267 94 my $new = $self->new_info;
268  
269 94 ▶ return 1 if ($old->{not_null} // 0) != ($new->{not_null} // 0);
Branch: 1 branch
BranchTrueFalseTotal
if ($old->{"not_null"} // 0) != ($new->{"not_null"} // 0) 15 79 94
Condition50%2/4
$old->{"not_null"} // 0
l!l
940
$new->{"not_null"} // 0
l!l
940
MC/DC0%0/1
$old->{"not_null"} // 0
$old->{"not_null"}
MC/DC0%0/1
$new->{"not_null"} // 0
$new->{"not_null"}
Truth table50%1/2
A
A= $old->{"not_null"}
Aresult
11
00
Truth table50%1/2
A
A= $new->{"not_null"}
Aresult
11
00
270  
271 79 my $old_type = _db2_column_type($old->{catalog_type}, $old->{catalog_size});
272 79 my $new_type = _db2_column_type($new->{catalog_type}, $new->{catalog_size});
273 79 ▶ return 0 if $old_type eq $new_type;
Branch: 1 branch
BranchTrueFalseTotal
if $old_type eq $new_type 19 60 79
274  
275 60 (my $old_name = $old_type) =~ s/\(.*\)\z//;
276 60 (my $new_name = $new_type) =~ s/\(.*\)\z//;
277 60 ▶ return 0 if $old_name eq $new_name && $LENGTH_CHANGE_WITHOUT_REORG{$new_name};
Branch: 1 branch
BranchTrueFalseTotal
if $old_name eq $new_name and $LENGTH_CHANGE_WITHOUT_REORG{$new_name} 14 46 60
Condition100%3/3
$old_name eq $new_name and $LENGTH_CHANGE_WITHOUT_REORG{$new_name}
!ll&&!rl&&r
341214
MC/DC100%2/2
$old_name eq $new_name and $LENGTH_CHANGE_WITHOUT_REORG{$new_name}
$old_name eq $new_name $LENGTH_CHANGE_WITHOUT_REORG{$new_name}
Truth table100%3/3
A and B
A= $old_name eq $new_nameB= $LENGTH_CHANGE_WITHOUT_REORG{$new_name}
ABresult
0X0
100
111
278  
279 46 return 1;
280 }
281  
282  
283 14 ▶sub summary {
Subroutine summary: called CC=2 SCAR=6.9
Pod documented
284 14 my ($self) = @_;
285 14 ▶ my $type = $self->new_info ? " ($self->{new_info}{catalog_type})" : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->new_info ? : 11 3 14
286 14 return sprintf ' %scolumn: %s.%s%s',
287 $self->summary_prefix, $self->table_name, $self->column_name, $type;
288 }
289  
290 47 1;
291  
292 __END__
« DB2/Introspect/Columns.pm ↑ Summary DB2/Storage.pm »