| 1 | package DBIO::Oracle::Diff::Column; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Diff operations for Oracle columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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::Oracle::Identifier (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 31 | ▶ | use DBIO::Diff::Compare qw(changed_fields column_change_lossy); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 31 | ▶ | use DBIO::Oracle::Type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 31 | __PACKAGE__->mk_diff_accessors(qw(table_name column_name old_info new_info)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # Canonical comparison key for a column default_value. Introspection stores | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # expression defaults as SCALAR refs (e.g. \'current_timestamp') and literal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # defaults as plain strings; a naive string compare stringifies the ref to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # SCALAR(0x...) and reports a phantom diff on every expression default. This | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # mirrors the rendering in as_sql so comparison and emission cannot diverge. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # Returns undef for the "no default" cases (undef input, literal "null", or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # the \'null' expression ref), so the core's desired_state semantics still | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # treat a target-undef as "don't care" and skip the field. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 542 | ▶ | sub _default_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_key: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 542 | my ($dv) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 542 | ▶ | return undef unless defined $dv; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 23 | ▶ | if (ref $dv eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | my $expr = lc $$dv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | $expr =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | $expr =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | return undef if $expr eq 'null'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | return $expr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 19 | ▶ | return undef if $dv eq 'null'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 19 | return DBIO::Oracle::Type::render_default_value($dv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 120 | ▶ | sub diff { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
diff: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 120 | my ($class, $source_cols, $target_cols, $source_tables, $target_tables) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 120 | my @ops; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 120 | for my $table_name (sort keys %$target_cols) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | next unless exists $source_tables->{$table_name} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 173 | ▶ | && exists $target_tables->{$table_name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $source_tables->{$table_name} and exists $target_tables->{$table_name}
MC/DC100%2/2
exists $source_tables->{$table_name} and exists $target_tables->{$table_name}
exists $source_tables->{$table_name}
exists $target_tables->{$table_name}
Truth table100%3/3
A and B
A= exists $source_tables->{$table_name}B= exists $target_tables->{$table_name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # The columns of a view follow from its definition, which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # DBIO::Oracle::Diff::View replaces as a whole (karr k65); ALTER TABLE does | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # not work on a view. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | next if ( $target_tables->{$table_name}{kind} // '' ) eq 'view' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 151 | ▶ | || ( $source_tables->{$table_name}{kind} // '' ) eq 'view'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition85%6/7
($target_tables->{$table_name}{"kind"} // "") eq "view" or ($source_tables->{$table_name}{"kind"} // "") eq "view"
$target_tables->{$table_name}{"kind"} // ""
$source_tables->{$table_name}{"kind"} // ""
MC/DC50%1/2
($target_tables->{$table_name}{"kind"} // "") eq "view" or ($source_tables->{$table_name}{"kind"} // "") 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 139 | ▶ | my %src_by_name = map { $_->{column_name} => $_ } @{ $source_cols->{$table_name} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$source_cols->{$table_name} // []
MC/DC0%0/1
$source_cols->{$table_name} // []
$source_cols->{$table_name}
Truth table50%1/2
A
A= $source_cols->{$table_name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 139 | ▶ | my %tgt_by_name = map { $_->{column_name} => $_ } @{ $target_cols->{$table_name} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$target_cols->{$table_name} // []
MC/DC0%0/1
$target_cols->{$table_name} // []
$target_cols->{$table_name}
Truth table50%1/2
A
A= $target_cols->{$table_name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 139 | for my $col_name (sort keys %tgt_by_name) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 239 | my $tgt = $tgt_by_name{$col_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 239 | ▶ | if (!exists $src_by_name{$col_name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 13 | push @ops, $class->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | action => 'add', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | table_name => $table_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | column_name => $col_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | new_info => $tgt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 13 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 226 | my $src = $src_by_name{$col_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | my @changed = _changed_column_fields($src, $tgt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 226 | defined $target_tables->{$table_name}{schema}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 226 | ▶ | next unless @changed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 25 | push @ops, $class->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | action => 'alter', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | table_name => $table_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | column_name => $col_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | old_info => $src, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | new_info => $tgt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 139 | for my $col_name (sort keys %src_by_name) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 233 | ▶ | next if exists $tgt_by_name{$col_name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | push @ops, $class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | action => 'drop', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | table_name => $table_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | column_name => $col_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 7 | old_info => $src_by_name{$col_name}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 120 | return @ops; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # Run the canonical changed_fields over data_type / not_null / default_value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # Pre-normalise default_value through _default_key so SCALAR-ref expression | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # defaults compare by content (the core would stringify refs to SCALAR(0x..)). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # A target that is the introspection of a database (its table entry carries the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # schema) states every column in full: a column without a default is a column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # without one, and the default the source has is removed (karr k63). A model | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # written by hand that states none leaves it alone, as the core's desired state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # does. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 226 | ▶ | sub _changed_column_fields { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_changed_column_fields: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 226 | my ($src, $tgt, $described) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 226 | my @changed = _core_changed_fields($src, $tgt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | push @changed, 'default_value' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | if $described && !defined _default_key($tgt->{default_value}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | && defined _default_key($src->{default_value}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | && !grep { $_ eq 'default_value' } @changed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$described and not defined _default_key($tgt->{"default_value"}) and defined _default_key($src->{"default_value"}) and not grep({$_ eq "default_value";} @changed)
$described and not defined _default_key($tgt->{"default_value"}) and defined _default_key($src->{"default_value"})
$described and not defined _default_key($tgt->{"default_value"})
MC/DC50%2/4
$described and not defined _default_key($tgt->{"default_value"}) and defined _default_key($src->{"default_value"}) and not grep({$_ eq "default_value";} @changed)
$described
not defined _default_key($tgt->{"default_value"})
defined _default_key($src->{"default_value"})
not grep({$_ eq "default_value";} @changed)
Truth table60%3/5
A and not(B) and C and not(D)
A= $describedB= not defined _default_key($tgt->{"default_value"})C= defined _default_key($src->{"default_value"})D= not grep({$_ eq "default_value";} @changed)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 226 | return @changed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 226 | ▶ | sub _core_changed_fields { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_core_changed_fields: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 226 | my ($src, $tgt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | return changed_fields( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | { %$src, default_value => _default_key($src->{default_value}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | size => _size_key($src), data_type => _type_key($src) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 226 | { %$tgt, default_value => _default_key($tgt->{default_value}), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | size => _size_key($tgt), data_type => _type_key($tgt) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | type => ['data_type'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | bool => ['not_null'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | scalar => ['default_value'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | dim => ['size'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | desired_state => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # The comparison key of a type: the Oracle type it is written as, sizes left | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # out (those are the size key's). varchar and varchar2, datetime and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # timestamp, real and binary_float are one type to the server; a difference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # that renders the same cannot be altered (karr k38). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 452 | ▶ | sub _type_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_type_key: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 452 | my ($info) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 452 | ▶ | return $info->{data_type} unless defined $info->{data_type}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 452 | return DBIO::Oracle::Type::map_dbio_type_to_oracle($info->{data_type}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # The comparison key of a size: what the server cannot keep apart is not a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # difference (karr k38). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # * NUMBER(p) is NUMBER(p,0): a numeric size of [p, 0] compares as p. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # * The defaults of an interval, YEAR(2) and DAY(2) TO SECOND(6), compare as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # no size, and a scale of undef is a scale of 0. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # * 6 on a timestamp and 126 on a float are the defaults, which the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # dictionary reports without a size: they compare as no size. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # * "20 CHAR" in any spelling is "20 CHAR", "20 BYTE" is 20 (BYTE is the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # default semantics); CHAR and BYTE stay a difference. A national type is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # of character semantics always, so its "5 CHAR" is 5. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 475 | ▶ | sub _size_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_size_key: called CC=23 SCAR=35.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 475 | my ($info) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 475 | my $size = $info->{size}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 475 | ▶ | my $type = lc($info->{data_type} // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$info->{"data_type"} // ""
MC/DC0%0/1
$info->{"data_type"} // ""
$info->{"data_type"}
Truth table50%1/2
A
A= $info->{"data_type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 475 | ▶ | return $size unless defined $size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 173 | ▶ | if (ref $size eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 5 | ▶ | return $size->[0] if $type =~ /^(?:numeric|decimal)\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
$type =~ /^(?:numeric|decimal)\z/ and @$size == 2 and !defined($size->[1]) || $size->[1] == 0
$type =~ /^(?:numeric|decimal)\z/ and @$size == 2
not defined $size->[1] or $size->[1] == 0
MC/DC25%1/4
$type =~ /^(?:numeric|decimal)\z/ and @$size == 2 and !defined($size->[1]) || $size->[1] == 0
$type =~ /^(?:numeric|decimal)\z/
@$size == 2
not defined $size->[1]
$size->[1] == 0
Truth table40%2/5
A and B and not(C) or D
A= $type =~ /^(?:numeric|decimal)\z/B= @$size == 2C= not defined $size->[1]D= $size->[1] == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | && @$size == 2 && (!defined $size->[1] || $size->[1] == 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 4 | ▶ | return undef if $type eq 'interval day to second' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition23%3/13
$type eq "interval day to second" and @$size == 2 and ($size->[0] // 2) == 2 and ($size->[1] // 6) == 6
$type eq "interval day to second" and @$size == 2 and ($size->[0] // 2) == 2
$type eq "interval day to second" and @$size == 2
$size->[0] // 2
$size->[1] // 6
MC/DC0%0/4
$type eq "interval day to second" and @$size == 2 and ($size->[0] // 2) == 2 and ($size->[1] // 6) == 6
$type eq "interval day to second"
@$size == 2
$size->[0]
$size->[1]
Truth table20%1/5
A and B and C and D
A= $type eq "interval day to second"B= @$size == 2C= $size->[0]D= $size->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | && @$size == 2 && ($size->[0] // 2) == 2 && ($size->[1] // 6) == 6; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 4 | return $size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 168 | ▶ | return undef if $size eq '6' && $type =~ /^(?:timestamp|datetime)/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$size eq 6 and $type =~ /^(?:timestamp|datetime)/
MC/DC100%2/2
$size eq 6 and $type =~ /^(?:timestamp|datetime)/
$size eq 6
$type =~ /^(?:timestamp|datetime)/
Truth table100%3/3
A and B
A= $size eq 6B= $type =~ /^(?:timestamp|datetime)/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 163 | ▶ | return undef if $size eq '126' && $type eq 'float'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$size eq 126 and $type eq "float"
MC/DC50%1/2
$size eq 126 and $type eq "float"
$size eq 126
$type eq "float"
Truth table66%2/3
A and B
A= $size eq 126B= $type eq "float"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 162 | ▶ | return undef if $size eq '2' && $type eq 'interval year to month'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$size eq 2 and $type eq "interval year to month"
MC/DC0%0/2
$size eq 2 and $type eq "interval year to month"
$size eq 2
$type eq "interval year to month"
Truth table33%1/3
A and B
A= $size eq 2B= $type eq "interval year to month"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 162 | ▶ | if ($size =~ /\A\s*(\d+)\s+(char|byte)\s*\z/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 7 | my ($n, $sem) = ($1, uc $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 7 | ▶ | return $n if $sem eq 'BYTE' || $type =~ /^n(?:var)?char2?\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$sem eq "BYTE" or $type =~ /^n(?:var)?char2?\z/
MC/DC100%2/2
$sem eq "BYTE" or $type =~ /^n(?:var)?char2?\z/
$sem eq "BYTE"
$type =~ /^n(?:var)?char2?\z/
Truth table100%3/3
A or B
A= $sem eq "BYTE"B= $type =~ /^n(?:var)?char2?\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 3 | return "$n CHAR"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 155 | return $size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # Render an info hashref's Oracle DDL type string with size baked in (e.g. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # VARCHAR2(100), NUMBER(12,2)). Used both to emit ADD COLUMN types and to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # detect MODIFY-worthy type changes -- comparing rendered strings (rather | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # than bare data_type) catches size-only changes like VARCHAR2(50) -> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # VARCHAR2(100), where data_type is identical on both sides. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 134 | ▶ | sub _rendered_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rendered_type: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 134 | my ($info) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 134 | return DBIO::Oracle::Type::map_dbio_type_to_oracle($info->{data_type}, size => $info->{size}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 24 | ▶ | sub as_sql { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_sql: called CC=19 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 24 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 24 | my $tbl = DBIO::Oracle::Identifier::quote_table($self->table_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 24 | my $col = DBIO::Oracle::Identifier::quote($self->column_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 24 | ▶ | if ($self->action eq 'add') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 10 | my $info = $self->new_info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 10 | my $type = _rendered_type($info); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 10 | my $sql = sprintf 'ALTER TABLE %s ADD (%s %s', $tbl, $col, $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 10 | ▶ | if (defined $info->{default_value} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $info->{"default_value"} and ref $info->{"default_value"} || $info->{"default_value"} ne "null"
ref $info->{"default_value"} or $info->{"default_value"} ne "null"
MC/DC33%1/3
defined $info->{"default_value"} and ref $info->{"default_value"} || $info->{"default_value"} ne "null"
defined $info->{"default_value"}
ref $info->{"default_value"}
$info->{"default_value"} ne "null"
Truth table50%2/4
A and B or C
A= defined $info->{"default_value"}B= ref $info->{"default_value"}C= $info->{"default_value"} ne "null"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | && (ref $info->{default_value} || $info->{default_value} ne 'null')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | $sql .= ' DEFAULT ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 2 | . DBIO::Oracle::Type::render_default_value($info->{default_value}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 10 | ▶ | $sql .= ' NOT NULL' if $info->{not_null}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 10 | $sql .= ')'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 10 | return "$sql;"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 14 | ▶ | if ($self->action eq 'drop') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # CASCADE CONSTRAINTS: a column that is part of a multi-column constraint | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # (a unique key over two columns) cannot be dropped without it (ORA-12991); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # the constraint goes with the column, as the target no longer has it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 6 | return sprintf 'ALTER TABLE %s DROP COLUMN %s CASCADE CONSTRAINTS;', $tbl, $col; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 8 | ▶ | if ($self->action eq 'alter') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 8 | my $old = $self->old_info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 8 | my $new = $self->new_info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 8 | my @stmts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | my @mods; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 8 | ▶ | if (_rendered_type($old) ne _rendered_type($new)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 4 | push @mods, _rendered_type($new); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 8 | ▶ | if (defined $new->{default_value}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | push @mods, 'DEFAULT ' . DBIO::Oracle::Type::render_default_value($new->{default_value}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 2 | ▶ | if ref $new->{default_value} || $new->{default_value} ne 'null'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $new->{"default_value"} or $new->{"default_value"} ne "null"
MC/DC0%0/2
ref $new->{"default_value"} or $new->{"default_value"} ne "null"
ref $new->{"default_value"}
$new->{"default_value"} ne "null"
Truth table33%1/3
A or B
A= ref $new->{"default_value"}B= $new->{"default_value"} ne "null"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | ▶ | elsif (!defined $new->{default_value} && defined $old->{default_value}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not defined $new->{"default_value"} and defined $old->{"default_value"}
MC/DC50%1/2
not defined $new->{"default_value"} and defined $old->{"default_value"}
not defined $new->{"default_value"}
defined $old->{"default_value"}
Truth table66%2/3
not(A) and B
A= not defined $new->{"default_value"}B= defined $old->{"default_value"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 1 | push @mods, 'DEFAULT NULL'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 8 | ▶ | if (($old->{not_null} // 0) != ($new->{not_null} // 0)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%4/4
$old->{"not_null"} // 0
$new->{"not_null"} // 0
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"}
Truth table100%2/2
A
A= $new->{"not_null"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 1 | ▶ | push @mods, $new->{not_null} ? 'NOT NULL' : 'NULL'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 8 | ▶ | if (@mods) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 8 | push @stmts, sprintf 'ALTER TABLE %s MODIFY (%s %s);', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | $tbl, $col, join(' ', @mods); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 8 | return join "\n", @stmts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 31 | our %LOSSLESS_PAIRS = map { $_ => 1 } qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | char->varchar2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | nchar->nvarchar2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | date->timestamp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # The column as column_change_lossy reads it: the Oracle base type in lower | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # case (varchar and varchar2, datetime and timestamp, real and binary_float are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # one type) and the size of the rendered type. The character types carry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # their length semantics apart, BYTE when none is written and always CHAR for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # a national type. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 104 | ▶ | sub _lossy_info { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lossy_info: called CC=16 SCAR=27.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 104 | my ($info) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | my $rendered = uc _rendered_type({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | data_type => $info->{data_type}, size => $info->{size}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 104 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 104 | my @inner = $rendered =~ /\(([^)]*)\)/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 104 | (my $base = $rendered) =~ s/\([^)]*\)//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 104 | $base =~ s/\s+/ /g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 104 | $base =~ s/\A | \z//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 104 | my %out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 104 | ▶ | if ($base eq 'INTEGER') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 6 | ($base, @inner) = ('NUMBER', '38,0'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 104 | ▶ | if ($base =~ /\A(?:N?CHAR|N?VARCHAR2)\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 54 | ▶ | my ($n, $sem) = ($inner[0] // '') =~ /\A\s*(\d+)(?:\s+(CHAR|BYTE))?\s*\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$inner[0] // ""
MC/DC0%0/1
$inner[0] // ""
$inner[0]
Truth table50%1/2
A
A= $inner[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | ? ($1, $2) : ($inner[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 54 | ▶ | $sem //= $base =~ /\AN/ ? 'CHAR' : 'BYTE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$sem //= $base =~ /\AN/ ? "CHAR" : "BYTE"
MC/DC100%1/1
$sem //= $base =~ /\AN/ ? "CHAR" : "BYTE"
$sem
Truth table100%2/2
A
A= $sem
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 54 | $out{sem} = $sem; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 54 | $out{size} = $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 50 | my $size = join ',', grep { length } @inner; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 50 | ▶ | $size .= ',0' if $base eq 'NUMBER' && length $size && $size !~ /,/; # NUMBER(p) is NUMBER(p,0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$base eq "NUMBER" and length $size and not $size =~ /,/
$base eq "NUMBER" and length $size
MC/DC100%3/3
$base eq "NUMBER" and length $size and not $size =~ /,/
$base eq "NUMBER"
length $size
not $size =~ /,/
Truth table100%4/4
A and B and not(C)
A= $base eq "NUMBER"B= length $sizeC= not $size =~ /,/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 50 | ▶ | $size = 6 if !length $size && $base =~ /\ATIMESTAMP/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not length $size and $base =~ /\ATIMESTAMP/
MC/DC100%2/2
not length $size and $base =~ /\ATIMESTAMP/
not length $size
$base =~ /\ATIMESTAMP/
Truth table100%3/3
not(A) and B
A= not length $sizeB= $base =~ /\ATIMESTAMP/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 50 | ▶ | $size = 126 if !length $size && $base eq 'FLOAT'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not length $size and $base eq "FLOAT"
MC/DC100%2/2
not length $size and $base eq "FLOAT"
not length $size
$base eq "FLOAT"
Truth table100%3/3
not(A) and B
A= not length $sizeB= $base eq "FLOAT"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 50 | ▶ | $out{size} = $size if length $size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 104 | ▶ | delete $out{size} unless defined $out{size}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 104 | return { data_type => lc $base, %out }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 57 | ▶ | sub lossy { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lossy: called CC=13 SCAR=25.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 57 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 57 | ▶ | return 0 unless $self->action eq 'alter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 52 | ▶ | my ($old, $new) = ($self->old_info // {}, $self->new_info // {}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$self->old_info // {}
$self->new_info // {}
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
Truth table50%1/2
A
A= $self->new_info
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 52 | ▶ | $new = { %$new, data_type => $old->{data_type} } unless defined $new->{data_type}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 52 | my ($o, $n) = (_lossy_info($old), _lossy_info($new)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 52 | ▶ | return 1 if defined $o->{sem} && defined $n->{sem} && $o->{sem} ne $n->{sem}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $o->{"sem"} and defined $n->{"sem"} and $o->{"sem"} ne $n->{"sem"}
defined $o->{"sem"} and defined $n->{"sem"}
MC/DC100%3/3
defined $o->{"sem"} and defined $n->{"sem"} and $o->{"sem"} ne $n->{"sem"}
defined $o->{"sem"}
defined $n->{"sem"}
$o->{"sem"} ne $n->{"sem"}
Truth table100%4/4
A and B and C
A= defined $o->{"sem"}B= defined $n->{"sem"}C= $o->{"sem"} ne $n->{"sem"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 45 | my $lossy = column_change_lossy($o, $n, \%LOSSLESS_PAIRS); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 45 | ▶ | if (!$lossy && $o->{data_type} ne $n->{data_type} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
not $lossy and $o->{"data_type"} ne $n->{"data_type"} and defined $o->{"size"} and defined $n->{"size"}
not $lossy and $o->{"data_type"} ne $n->{"data_type"} and defined $o->{"size"}
not $lossy and $o->{"data_type"} ne $n->{"data_type"}
MC/DC75%3/4
not $lossy and $o->{"data_type"} ne $n->{"data_type"} and defined $o->{"size"} and defined $n->{"size"}
not $lossy
$o->{"data_type"} ne $n->{"data_type"}
defined $o->{"size"}
defined $n->{"size"}
Truth table80%4/5
not(A) and B and C and D
A= not $lossyB= $o->{"data_type"} ne $n->{"data_type"}C= defined $o->{"size"}D= defined $n->{"size"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | && defined $o->{size} && defined $n->{size}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | $lossy = column_change_lossy( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | { data_type => 'x', size => $o->{size} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | { data_type => 'x', size => $n->{size} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 45 | ▶ | return $lossy ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 4 | ▶ | sub summary { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
summary: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 4 | ▶ | my $type = $self->new_info ? " ($self->{new_info}{data_type})" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 4 | return sprintf ' %scolumn: %s.%s%s', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | $self->summary_prefix, $self->table_name, $self->column_name, $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 31 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||