MSSQL/Diff/Column.pm

filter: Statementstmt 99.3% 158 / 159 Branchbran 89.5% 77 / 86 Conditioncond 57.9% 40 / 69 MC/DCmcdc 26.8% 11 / 41 Subroutinesub 100% 25 / 25 Podpod 100% 6 / 6 totaltotal 82.1% 317 / 386 CC 71 SCAR 24.0
CC
71
Cov
88%
as_sql
25.7
unbinds_dependents
12.4
lossy
8.2
CRAP 11.0
« MSSQL/Storage/Sybase.pm ↑ Summary MSSQL/Diff/Index.pm »
1 package DBIO::MSSQL::Diff::Column;
2 # ABSTRACT: Diff operations for MSSQL columns
3  
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 40 our $VERSION = '0.900007';
8  
9 40 ▶use base 'DBIO::Diff::Op';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 40 ▶use DBIO::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 40 ▶use DBIO::MSSQL::DDL qw(_mssql_column_type _quote_ident _quote_table _bare_table);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 40 ▶use DBIO::MSSQL::Diff::Table ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 40 ▶use DBIO::Diff::Compare qw(changed_column_fields column_change_lossy);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18 40 __PACKAGE__->mk_diff_accessors(qw/table_name column_name old_info new_info/);
19  
20  
21 130 ▶sub diff {
Subroutine diff: called CC=4 SCAR=13.9
Pod documented
22 130 my ($class, $source_cols, $target_cols, $source_tables, $target_tables) = @_;
23  
24 # a view has no ALTER TABLE ... ADD/DROP COLUMN; Diff::View replaces it (karr k82)
25 130 my %is_view = map { $_ => 1 }
26 DBIO::MSSQL::Diff::Table->view_names($source_tables, $target_tables);
27 130 ▶ if (%is_view) {
Branch: 1 branch
BranchTrueFalseTotal
if (%is_view) 17 113 130
28 17 ▶ $source_cols = { map { $_ => $source_cols->{$_} } grep { !$is_view{$_} } keys %{ $source_cols // {} } };
Condition50%1/2
$source_cols // {}
l!l
170
MC/DC0%0/1
$source_cols // {}
$source_cols
Truth table50%1/2
A
A= $source_cols
Aresult
11
00
29 17 ▶ $target_cols = { map { $_ => $target_cols->{$_} } grep { !$is_view{$_} } keys %{ $target_cols // {} } };
Condition50%1/2
$target_cols // {}
l!l
170
MC/DC0%0/1
$target_cols // {}
$target_cols
Truth table50%1/2
A
A= $target_cols
Aresult
11
00
30 }
31  
32 return $class->diff_nested($source_cols, $target_cols,
33 index_by => 'column_name',
34 scope => 'both',
35 source_tables => $source_tables,
36 target_tables => $target_tables,
37 179 ▶ changed_when => sub { scalar changed_column_fields($_[0], $_[1]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
38 8 ▶ on_new => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
39 8 my ($table, $name, $new) = @_;
40 8 $class->new(action => 'add', table_name => $table, column_name => $name, new_info => $new);
41 },
42 60 ▶ on_changed => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
43 60 my ($table, $name, $old, $new) = @_;
44 60 $class->new(action => 'alter', table_name => $table, column_name => $name,
45 old_info => $old, new_info => $new);
46 },
47 4 ▶ on_gone => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
48 4 my ($table, $name, $old) = @_;
49 4 $class->new(action => 'drop', table_name => $table, column_name => $name, old_info => $old);
50 },
51 130 );
52 }
53  
54  
55 40 our %LOSSLESS_PAIRS;
56 {
57 40 my @ladder = qw(tinyint smallint int bigint);
58 40 for my $from (0 .. $#ladder - 1) {
59 120 $LOSSLESS_PAIRS{"$ladder[$from]->$ladder[$_]"} = 1 for $from + 1 .. $#ladder;
60 }
61 40 $LOSSLESS_PAIRS{'date->datetime2'} = 1;
62 }
63  
64 # string types that become another one of the same content without loss while
65 # the length stays or grows
66 40 my %SAME_FAMILY = map { $_ => 1 } qw(
67 char->varchar char->nchar char->nvarchar varchar->nvarchar nchar->nvarchar
68 binary->varbinary
69 );
70  
71 40 my %ALIAS = (integer => 'int', numeric => 'decimal', bool => 'bit', boolean => 'bit');
72  
73  
74 17 ▶sub lossy {
Subroutine lossy: called CC=8 SCAR=21.1
Pod documented
75 17 my ($self) = @_;
76 17 ▶ return 0 unless $self->action eq 'alter';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->action eq "alter" 1 16 17
77 16 ▶ return 0 unless $self->retypes;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->retypes 4 12 16
78 12 ▶ my ($old, $new) = ($self->old_info // {}, $self->new_info // {});
Condition50%2/4
$self->old_info // {}
l!l
120
$self->new_info // {}
l!l
120
MC/DC0%0/1
$self->old_info // {}
$self->old_info
MC/DC0%0/1
$self->new_info // {}
$self->new_info
Truth table50%1/2
A
A= $self->old_info
Aresult
11
00
Truth table50%1/2
A
A= $self->new_info
Aresult
11
00
79  
80 12 ▶ my $base = sub { my $t = lc($_[0] // ''); $t =~ s/\s.*\z//s; $ALIAS{$t} // $t };
Subroutine __ANON__: called CC=3 SCAR=12.0
Condition40%2/5
$_[0] // ""
l!l
240
$ALIAS{$t} // $t
l!l&&r!l&&!r
0240
MC/DC0%0/1
$_[0] // ""
$_[0]
MC/DC0%0/2
$ALIAS{$t} // $t
$ALIAS{$t} $t
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
Truth table33%1/3
A // B
A= $ALIAS{$t}B= $t
ABresult
1X1
011
000
81 12 my ($ot, $nt) = ($base->($old->{data_type}), $base->($new->{data_type}));
82 12 ▶ $nt = $ot unless length $nt;
Branch: 1 branch
BranchTrueFalseTotal
unless length $nt 0 12 12
83  
84 # max is longer than any number
85 24 ▶ my $len = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
86 24 my $s = $_[0];
87 24 ▶ return $s unless defined $s && !ref $s && $s =~ /\A\s*-1\s*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s and $s =~ /\A\s*-1\s*\z/ 22 2 24
Condition83%5/6
defined $s and not ref $s and $s =~ /\A\s*-1\s*\z/
!ll&&!rl&&r
11112
defined $s and not ref $s
!ll&&!rl&&r
11013
MC/DC66%2/3
defined $s and not ref $s and $s =~ /\A\s*-1\s*\z/
defined $s not ref $s $s =~ /\A\s*-1\s*\z/
Truth table75%3/4
A and not(B) and C
A= defined $sB= not ref $sC= $s =~ /\A\s*-1\s*\z/
ABCresult
0XX0
10X0
1100
1111
88 2 return 2**31;
89 12 };
90 12 my %o = (data_type => $ot, size => $len->($old->{size}));
91 12 my %n = (data_type => $nt, size => $len->($new->{size}));
92 12 ▶ $n{data_type} = $ot if $SAME_FAMILY{"$ot->$nt"};
Branch: 1 branch
BranchTrueFalseTotal
if $SAME_FAMILY{"$ot->$nt"} 1 11 12
93  
94 12 ▶ return column_change_lossy(\%o, \%n, \%LOSSLESS_PAIRS) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
column_change_lossy(\%o, \%n, \%DBIO::MSSQL::Diff::Column::LOSSLESS_PAIRS) ? : 6 6 12
95 }
96  
97  
98 48 ▶sub retypes {
Subroutine retypes: called CC=7 SCAR=19.9
Pod documented
99 48 my ($self) = @_;
100 48 ▶ return 0 unless $self->action eq 'alter';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->action eq "alter" 7 41 48
101 41 ▶ my $old = $self->old_info || {};
Condition50%1/2
$self->old_info || {}
l!l
410
MC/DC0%0/1
$self->old_info || {}
$self->old_info
Truth table50%1/2
A
A= $self->old_info
Aresult
11
00
102 41 ▶ my $new = $self->new_info || {};
Condition50%1/2
$self->new_info || {}
l!l
410
MC/DC0%0/1
$self->new_info || {}
$self->new_info
Truth table50%1/2
A
A= $self->new_info
Aresult
11
00
103 41 ▶ my $want = sub { defined $new->{$_[0]} ? $new->{$_[0]} : $old->{$_[0]} };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $$new{$_[0]} ? : 56 26 82
104 41 my $dt = $want->('data_type');
105 41 ▶ return 0 unless defined $dt && defined $old->{data_type};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dt and defined $old->{"data_type"} 0 41 41
Condition33%1/3
defined $dt and defined $old->{"data_type"}
!ll&&!rl&&r
0041
MC/DC0%0/2
defined $dt and defined $old->{"data_type"}
defined $dt defined $old->{"data_type"}
Truth table33%1/3
A and B
A= defined $dtB= defined $old->{"data_type"}
ABresult
0X0
100
111
106 41 my $nt = $self->_alter_column_type({ data_type => $dt, size => $want->('size') }, 'desired');
107 41 my $ot = $self->_alter_column_type($old, 'live');
108 41 ▶ return $nt ne $ot ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$nt ne $ot ? : 22 19 41
109 }
110  
111  
112 38 ▶sub unbinds_dependents {
Subroutine unbinds_dependents: called CC=12 SCAR=25.1
Pod documented
113 38 my ($self) = @_;
114 38 ▶ return 0 unless $self->action eq 'alter';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->action eq "alter" 7 31 38
115 31 ▶ my $old = $self->old_info || {};
Condition50%1/2
$self->old_info || {}
l!l
310
MC/DC0%0/1
$self->old_info || {}
$self->old_info
Truth table50%1/2
A
A= $self->old_info
Aresult
11
00
116 31 ▶ my $new = $self->new_info || {};
Condition50%1/2
$self->new_info || {}
l!l
310
MC/DC0%0/1
$self->new_info || {}
$self->new_info
Truth table50%1/2
A
A= $self->new_info
Aresult
11
00
117 31 ▶ my $want = sub { defined $new->{$_[0]} ? $new->{$_[0]} : $old->{$_[0]} };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $$new{$_[0]} ? : 56 13 69
118 31 ▶ my $new_nn = $want->('not_null') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
&$want('not_null') ? : 23 8 31
119 31 ▶ return 1 if $new_nn && !$old->{not_null};
Branch: 1 branch
BranchTrueFalseTotal
if $new_nn and not $old->{"not_null"} 12 19 31
Condition100%3/3
$new_nn and not $old->{"not_null"}
!ll&&!rl&&r
81112
MC/DC100%2/2
$new_nn and not $old->{"not_null"}
$new_nn not $old->{"not_null"}
Truth table100%3/3
A and not(B)
A= $new_nnB= not $old->{"not_null"}
ABresult
0X0
100
111
120 19 my $dt = $want->('data_type');
121 19 ▶ return 0 unless defined $dt && defined $old->{data_type};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dt and defined $old->{"data_type"} 0 19 19
Condition33%1/3
defined $dt and defined $old->{"data_type"}
!ll&&!rl&&r
0019
MC/DC0%0/2
defined $dt and defined $old->{"data_type"}
defined $dt defined $old->{"data_type"}
Truth table33%1/3
A and B
A= defined $dtB= defined $old->{"data_type"}
ABresult
0X0
100
111
122 19 my $nt = $self->_alter_column_type({ data_type => $dt, size => $want->('size') }, 'desired');
123 19 my $ot = $self->_alter_column_type($old, 'live');
124 19 ▶ return 0 if $nt eq $ot;
Branch: 1 branch
BranchTrueFalseTotal
if $nt eq $ot 7 12 19
125 12 my ($nb) = lc($nt) =~ /\A(\w+)/;
126 12 my ($ob) = lc($ot) =~ /\A(\w+)/;
127 12 ▶ return 0 if $nb eq $ob && $nb =~ /\A(?:nvarchar|varchar|varbinary)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $nb eq $ob and $nb =~ /\A(?:nvarchar|varchar|varbinary)\z/ 7 5 12
Condition66%2/3
$nb eq $ob and $nb =~ /\A(?:nvarchar|varchar|varbinary)\z/
!ll&&!rl&&r
507
MC/DC50%1/2
$nb eq $ob and $nb =~ /\A(?:nvarchar|varchar|varbinary)\z/
$nb eq $ob $nb =~ /\A(?:nvarchar|varchar|varbinary)\z/
Truth table66%2/3
A and B
A= $nb eq $obB= $nb =~ /\A(?:nvarchar|varchar|varbinary)\z/
ABresult
0X0
100
111
128 5 return 1;
129 }
130  
131  
132 67 ▶sub as_sql {
Subroutine as_sql: called CC=25 SCAR=32.5
Pod documented
133 67 my ($self) = @_;
134  
135 67 my $tbl = _quote_table($self->table_name);
136 67 my $col = _quote_ident($self->column_name);
137  
138 67 ▶ if ($self->action eq 'add') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->action eq "add") 7 60 67
139 7 my $info = $self->new_info;
140 7 my $type = _mssql_column_type($info, $self->table_name, $self->column_name);
141 6 my $sql = sprintf 'ALTER TABLE %s ADD %s %s', $tbl, $col, $type;
142 6 ▶ $sql .= ' NOT NULL' if $info->{not_null};
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"not_null"} 2 4 6
143 6 ▶ if (defined $info->{default_value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"default_value"}) 0 6 6
144 0 $sql .= " DEFAULT $info->{default_value}";
145 }
146 6 return "$sql;";
147 }
148  
149 60 ▶ if ($self->action eq 'drop') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->action eq "drop") 4 56 60
150 4 return sprintf 'ALTER TABLE %s DROP COLUMN %s;', $tbl, $col;
151 }
152  
153 56 ▶ if ($self->action eq 'alter') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->action eq "alter") 56 0 56
154 56 ▶ my $old = $self->old_info || {};
Condition50%1/2
$self->old_info || {}
l!l
560
MC/DC0%0/1
$self->old_info || {}
$self->old_info
Truth table50%1/2
A
A= $self->old_info
Aresult
11
00
155 56 ▶ my $new = $self->new_info || {};
Condition50%1/2
$self->new_info || {}
l!l
560
MC/DC0%0/1
$self->new_info || {}
$self->new_info
Truth table50%1/2
A
A= $self->new_info
Aresult
11
00
156 56 my @stmts;
157  
158 # The desired state of one field, read the way the comparator that decided
159 # this op exists reads it: a field the target leaves undef was not
160 # prescribed, so the live value stands (DBIO::Diff::Compare, desired-state
161 # contract). Per FIELD, not per hashref -- a target naming a type but no
162 # size must keep the live length, because a bare nvarchar in a column
163 # definition is not "unbounded", it is nvarchar(1) (karr k28).
164 168 ▶ my $want = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
165 168 my ($field) = @_;
166 168 ▶ return defined $new->{$field} ? $new->{$field} : $old->{$field};
Branch: 1 branch
BranchTrueFalseTotal
defined $new->{$field} ? : 103 65 168
167 56 };
168  
169 56 my %want_type = (data_type => $want->('data_type'), size => $want->('size'));
170 56 ▶ my $old_nn = $old->{not_null} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$old->{'not_null'} ? : 18 38 56
171 56 ▶ my $new_nn = $want->('not_null') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
&$want('not_null') ? : 28 28 56
172  
173 # The RENDERED type is the trigger, not the bare data_type string:
174 # INFORMATION_SCHEMA keeps the width in CHARACTER_MAXIMUM_LENGTH, so
175 # nvarchar(64) -> nvarchar(128) has the same data_type on both sides and
176 # fell through every branch, leaving as_sql returning the empty string
177 # while the diff still reported a change (karr k30).
178 56 my ($retype, $new_type) = (0, undef);
179 56 ▶ if (defined $want_type{data_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $want_type{"data_type"}) 54 2 56
180 54 $new_type = $self->_alter_column_type(\%want_type, 'desired');
181 $retype = !defined $old->{data_type}
182 52 ▶ || $new_type ne $self->_alter_column_type($old, 'live');
Condition66%2/3
!defined($old->{'data_type'}) || $new_type ne $self->_alter_column_type($old, 'live')
l!l&&r!l&&!r
02428
MC/DC50%1/2
!defined($old->{'data_type'}) || $new_type ne $self->_alter_column_type($old, 'live')
!defined($old->{'data_type'}) $new_type ne $self->_alter_column_type($old, 'live')
Truth table66%2/3
not(A) || B
A= !defined($old->{'data_type'})B= $new_type ne $self->_alter_column_type($old, 'live')
ABresult
1X1
011
000
183 }
184  
185 # One statement, always carrying both -- see L</ALTER COLUMN IS ONE
186 # STATEMENT>. Emitted only when something in it actually moved, so a
187 # default-only change does not drag a pointless retype along.
188 54 ▶ if ($retype || $old_nn != $new_nn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retype or $old_nn != $new_nn) 45 9 54
Condition100%3/3
$retype or $old_nn != $new_nn
l!l&&r!l&&!r
24219
MC/DC100%2/2
$retype or $old_nn != $new_nn
$retype $old_nn != $new_nn
Truth table100%3/3
A or B
A= $retypeB= $old_nn != $new_nn
ABresult
1X1
011
000
189 45 ▶ DBIO::Exception->throw(sprintf(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $new_type 2 43 45
190 "DBIO::MSSQL: ALTER COLUMN of column '%s' of table '%s' (%s.%s) is "
191 . 'refused: Transact-SQL requires a new_data_type there and neither '
192 . 'the desired nor the live column info names one',
193 $self->column_name, $self->table_name,
194 $self->table_name, $self->column_name,
195 )) unless defined $new_type;
196  
197 43 ▶ push @stmts, sprintf 'ALTER TABLE %s ALTER COLUMN %s %s %s;',
Branch: 1 branch
BranchTrueFalseTotal
$new_nn ? : 26 17 43
198 $tbl, $col, $new_type, ($new_nn ? 'NOT NULL' : 'NULL');
199 }
200  
201 # A default is a named CONSTRAINT in this dialect, never a clause of ALTER
202 # COLUMN (karr k31). The drop is unshifted ahead of any retype because SQL
203 # Server refuses to change the data type of a column that is "associated
204 # with a default definition".
205 52 my $new_d = $new->{default_value};
206 52 ▶ if (defined $new_d && length $new_d) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $new_d and length $new_d) { } 6 46 52
elsif (_is_real_default($old->{'default_value'})) { } 3 43 46
Condition66%2/3
defined $new_d and length $new_d
!ll&&!rl&&r
4606
MC/DC50%1/2
defined $new_d and length $new_d
defined $new_d length $new_d
Truth table66%2/3
A and B
A= defined $new_dB= length $new_d
ABresult
0X0
100
111
207 6 my $old_d = $old->{default_value};
208 6 ▶ if (!defined $old_d || $old_d ne $new_d) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $old_d or $old_d ne $new_d) 6 0 6
Condition66%2/3
not defined $old_d or $old_d ne $new_d
l!l&&r!l&&!r
240
MC/DC0%0/2
not defined $old_d or $old_d ne $new_d
not defined $old_d $old_d ne $new_d
Truth table66%2/3
not(A) or B
A= not defined $old_dB= $old_d ne $new_d
ABresult
1X1
011
000
209 6 ▶ if (defined $old_d && length $old_d) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old_d and length $old_d) 4 2 6
Condition66%2/3
defined $old_d and length $old_d
!ll&&!rl&&r
204
MC/DC50%1/2
defined $old_d and length $old_d
defined $old_d length $old_d
Truth table66%2/3
A and B
A= defined $old_dB= length $old_d
ABresult
0X0
100
111
210 my $live_name = $old->{default_constraint_name}
211 4 ▶ or DBIO::Exception->throw(sprintf(
Branch: 1 branch
BranchTrueFalseTotal
my $live_name = $old->{"default_constraint_name"} or "DBIO::Exception"->throw(sprintf("DBIO::MSSQL: replacing the DEFAULT of column '%s' of table '%s' (%s.%s) is refused: Transact-SQL drops a default by CONSTRAINT NAME and the live column info carries no default_constraint_name", $self->column_name, $self->table_name, $self->table_name, $self->column_name)) 2 2 4
212 "DBIO::MSSQL: replacing the DEFAULT of column '%s' of table '%s' "
213 . '(%s.%s) is refused: Transact-SQL drops a default by '
214 . 'CONSTRAINT NAME and the live column info carries no '
215 . 'default_constraint_name',
216 $self->column_name, $self->table_name,
217 $self->table_name, $self->column_name,
218 ));
219 2 unshift @stmts, sprintf 'ALTER TABLE %s DROP CONSTRAINT %s;',
220 $tbl, _quote_ident($live_name);
221 }
222 4 push @stmts, sprintf 'ALTER TABLE %s ADD CONSTRAINT %s DEFAULT %s FOR %s;',
223 $tbl, _quote_ident($self->_default_constraint_name($new)), $new_d, $col;
224 }
225 }
226  
227 # A default the target no longer declares is removed (core karr k367,
228 # karr k83): the comparator reports it, the live name drops it. A live
229 # DEFAULT NULL counts as none, as in the comparator.
230 elsif (_is_real_default($old->{default_value})) {
231 my $live_name = $old->{default_constraint_name}
232 3 ▶ or DBIO::Exception->throw(sprintf(
Branch: 1 branch
BranchTrueFalseTotal
my $live_name = $old->{"default_constraint_name"} or "DBIO::Exception"->throw(sprintf("DBIO::MSSQL: removing the DEFAULT of column '%s' of table '%s' (%s.%s) is refused: Transact-SQL drops a default by CONSTRAINT NAME and the live column info carries no default_constraint_name", $self->column_name, $self->table_name, $self->table_name, $self->column_name)) 2 1 3
233 "DBIO::MSSQL: removing the DEFAULT of column '%s' of table '%s' "
234 . '(%s.%s) is refused: Transact-SQL drops a default by '
235 . 'CONSTRAINT NAME and the live column info carries no '
236 . 'default_constraint_name',
237 $self->column_name, $self->table_name,
238 $self->table_name, $self->column_name,
239 ));
240 2 unshift @stmts, sprintf 'ALTER TABLE %s DROP CONSTRAINT %s;',
241 $tbl, _quote_ident($live_name);
242 }
243  
244 49 return join "\n", @stmts;
245 }
246 }
247  
248 # True for a live default that is one: not absent, not a literal NULL
249 # ("(NULL)", "((NULL))", \'NULL'), the way DBIO::Diff::Compare reads it.
250 46 ▶sub _is_real_default {
Subroutine _is_real_default: called CC=7 SCAR=20.0
251 46 my ($v) = @_;
252 46 ▶ $v = $$v if ref($v) eq 'SCALAR' || ref($v) eq 'REF';
Branch: 1 branch
BranchTrueFalseTotal
if ref $v eq "SCALAR" or ref $v eq "REF" 0 46 46
Condition33%1/3
ref $v eq "SCALAR" or ref $v eq "REF"
l!l&&r!l&&!r
0046
MC/DC0%0/2
ref $v eq "SCALAR" or ref $v eq "REF"
ref $v eq "SCALAR" ref $v eq "REF"
Truth table33%1/3
A or B
A= ref $v eq "SCALAR"B= ref $v eq "REF"
ABresult
1X1
011
000
253 46 ▶ return 0 unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 42 4 46
254 4 $v =~ s/\A\s+|\s+\z//g;
255 4 ▶ 1 while $v =~ s/\A\(\s*(.*?)\s*\)\z/$1/s;
Branch: 1 branch
BranchTrueFalseTotal
$v =~ s/\A\(\s*(.*?)\s*\)\z/$1/s and do { '???' } 7 4 11
256 4 ▶ return length $v && uc($v) ne 'NULL' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
length $v && uc $v ne 'NULL' ? : 3 1 4
Condition66%2/3
length $v and uc $v ne "NULL"
!ll&&!rl&&r
013
MC/DC50%1/2
length $v and uc $v ne "NULL"
length $v uc $v ne "NULL"
Truth table66%2/3
A and B
A= length $vB= uc $v ne "NULL"
ABresult
0X0
100
111
257 }
258  
259 # _mssql_column_type with the column named in whatever it refuses. A type the
260 # renderer cannot produce has no silent fallback here: the bare type name it
261 # would otherwise return is a one-character column in T-SQL, so refusing is the
262 # only reading that does not quietly change the data model.
263 226 ▶sub _alter_column_type {
Subroutine _alter_column_type: called CC=3 SCAR=11.0
264 226 my ($self, $info, $side) = @_;
265 226 my $type = eval { _mssql_column_type($info) };
266 226 ▶ return $type if defined $type;
Branch: 1 branch
BranchTrueFalseTotal
if defined $type 224 2 226
267 2 ▶ my $err = $@ || "unknown error\n";
Condition50%1/2
$@ || "unknown error\n"
l!l
20
MC/DC0%0/1
$@ || "unknown error\n"
$@
Truth table50%1/2
A
A= $@
Aresult
11
00
268 2 $err =~ s/\s+\z//;
269 2 DBIO::Exception->throw(sprintf
270 "DBIO::MSSQL: ALTER COLUMN of column '%s' of table '%s' (%s.%s) is refused: "
271 . 'cannot render the %s type: %s',
272 $self->column_name, $self->table_name,
273 $self->table_name, $self->column_name, $side, $err);
274 }
275  
276 # The name the new DEFAULT constraint is created under. Named rather than left
277 # to the server so a later diff can drop it without introspection; a target
278 # that carries a name of its own keeps it.
279 4 ▶sub _default_constraint_name {
Subroutine _default_constraint_name: called CC=3 SCAR=12.5
280 4 my ($self, $info) = @_;
281 return $info->{default_constraint_name}
282 4 ▶ if defined $info->{default_constraint_name} && length $info->{default_constraint_name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $info->{"default_constraint_name"} and length $info->{"default_constraint_name"} 0 4 4
Condition33%1/3
defined $info->{"default_constraint_name"} and length $info->{"default_constraint_name"}
!ll&&!rl&&r
400
MC/DC0%0/2
defined $info->{"default_constraint_name"} and length $info->{"default_constraint_name"}
defined $info->{"default_constraint_name"} length $info->{"default_constraint_name"}
Truth table33%1/3
A and B
A= defined $info->{"default_constraint_name"}B= length $info->{"default_constraint_name"}
ABresult
0X0
100
111
283 4 return sprintf 'DF_%s_%s', _bare_table($self->table_name), $self->column_name;
284 }
285  
286  
287 1 ▶sub summary {
Subroutine summary: called CC=2 SCAR=7.1
Pod documented
288 1 my ($self) = @_;
289 1 ▶ my $type = $self->new_info ? ' (' . $self->new_info->{data_type} . ')' : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->new_info ? : 1 0 1
290 1 return sprintf ' %scolumn: %s.%s%s',
291 $self->summary_prefix, $self->table_name, $self->column_name, $type;
292 }
293  
294 40 1;
295  
296 __END__
« MSSQL/Storage/Sybase.pm ↑ Summary MSSQL/Diff/Index.pm »