blib/lib/DBIO/MySQL/DDL.pm

filter: Statementstmt 99.3% 475 / 478 Branchbran 85.5% 202 / 236 Conditioncond 71.6% 149 / 208 MC/DCmcdc 50.8% 59 / 116 Subroutinesub 100% 28 / 28 Podpod 100% 10 / 10 totaltotal 85.7% 923 / 1076 CC 218 SCAR 38.0
CC
218
Cov
90%
install_ddl
101.8
view_reads
32.3
_mysql_column_type
28.3
CRAP 44.9
« xbin/dbio-mysql-k8s ↑ Summary blib/lib/DBIO/MySQL/Introspect/Indexes.pm »
1 package DBIO::MySQL::DDL;
2 # ABSTRACT: Generate MySQL/MariaDB DDL from DBIO Result classes
3  
4 86 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 86 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 86 our $VERSION = '0.900007';
8  
9 86 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 86 ▶use Digest::SHA ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 86 ▶use DBIO::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 86 ▶use DBIO::Schema::Type ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 86 ▶use DBIO::MySQL::Adapter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 86 ▶use DBIO::MySQL::Identifier qw(quote_ident check_table_name split_table_name quote_table);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 86 ▶use DBIO::MySQL::DefaultValue qw(default_sql);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 86 ▶use DBIO::MySQL::IndexType ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 86 my $ADAPTER = DBIO::MySQL::Adapter->new;
21  
22  
23  
24 196 ▶sub default_charset { 'utf8mb4' }
Subroutine default_charset: called CC=1 SCAR=0.0
Pod documented
25 196 ▶sub default_collation { 'utf8mb4_unicode_ci' }
Subroutine default_collation: called CC=1 SCAR=0.0
Pod documented
26  
27 86 my %FK_ACTION = map { $_ => 1 } ('NO ACTION', 'RESTRICT', 'CASCADE', 'SET NULL', 'SET DEFAULT');
28  
29 # The longest name of a constraint on MySQL and MariaDB.
30 86 my $MAX_NAME = 64;
31  
32  
33 138 ▶sub foreign_key_name {
Subroutine foreign_key_name: called CC=2 SCAR=6.9
Pod documented
34 138 my ($table, @cols) = @_;
35 138 my $name = join '_', $table, @cols, 'fk';
36 138 ▶ return $name if length $name <= $MAX_NAME;
Branch: 1 branch
BranchTrueFalseTotal
if length $name <= $MAX_NAME 130 8 138
37 8 my $hash = substr Digest::SHA::sha1_hex($name), 0, 8;
38 8 return substr($name, 0, $MAX_NAME - 9) . "_$hash";
39 }
40  
41  
42 71 ▶sub foreign_key_names {
Subroutine foreign_key_names: called CC=9 SCAR=22.0
Pod documented
43 71 my @fk = @_;
44 194 ▶ my $key = sub { join "\x1e", $_[0]{table}, join("\x1f", @{ $_[0]{from_columns} }),
Subroutine __ANON__: called CC=1 SCAR=0.0
45 71 $_[0]{to_table}, join("\x1f", @{ $_[0]{to_columns} }) };
46 71 ▶ my $full = sub { join "\x1e", $key->($_[0]), map { uc($_[0]{$_} // '') } qw/on_update on_delete/ };
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]{$_} // ""
l!l
22832
MC/DC100%1/1
$_[0]{$_} // ""
$_[0]{$_}
Truth table100%2/2
A
A= $_[0]{$_}
Aresult
11
00
47  
48 71 my (%distinct, @distinct); # identity => fk, in first-seen order
49 71 for my $fk (@fk) {
50 65 my $id = $full->($fk);
51 65 ▶ next if $distinct{$id};
Branch: 1 branch
BranchTrueFalseTotal
if $distinct{$id} 4 61 65
52 61 $distinct{$id} = $fk;
53 61 push @distinct, $id;
54 }
55  
56 71 my %by_name; # lc(plain name) => [ identity ... ]
57 61 push @{ $by_name{ lc foreign_key_name($distinct{$_}{table}, @{ $distinct{$_}{from_columns} }) } }, $_
58 71 for @distinct;
59  
60 71 my %name;
61 71 for my $id (@distinct) {
62 61 my $fk = $distinct{$id};
63 61 my $plain = foreign_key_name($fk->{table}, @{ $fk->{from_columns} });
64 61 my @group = @{ $by_name{ lc $plain } };
65 61 ▶ if (@group == 1) { $name{$id} = $plain; next }
Branch: 1 branch
BranchTrueFalseTotal
if (@group == 1) 45 16 61
66 16 my %four; $four{ $key->($distinct{$_}) }++ for @group;
67 16 ▶ my $hash = substr Digest::SHA::sha1_hex($four{ $key->($fk) } > 1 ? $id : $key->($fk)), 0, 8;
Branch: 1 branch
BranchTrueFalseTotal
$four{&$key($fk)} > 1 ? : 0 16 16
68 16 ▶ $name{$id} = (length "${plain}_$hash" <= $MAX_NAME ? $plain : substr($plain, 0, $MAX_NAME - 9)) . "_$hash";
Branch: 1 branch
BranchTrueFalseTotal
length "${plain}_$hash" <= $MAX_NAME ? : 14 2 16
69 }
70 71 return map { $name{ $full->($_) } } @fk;
71 }
72  
73 # The columns of a foreign key in the order of the key of the target: InnoDB
74 # takes the referenced list only in the order of an index (any other order is
75 # "Missing index"). The primary key is asked first, then the unique constraints
76 # by name; the first whose column set is the referenced one gives the order,
77 # the pairing with the referencing columns kept. None: as given (sorted by the
78 # target names); one column: nothing to order.
79 66 ▶sub _order_by_target_key {
Subroutine _order_by_target_key: called CC=7 SCAR=19.6
80 66 my ($foreign, $from, $to) = @_;
81 66 ▶ return ($from, $to) if @$to < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @$to < 2 63 3 66
82 3 my %pair; @pair{@$to} = @$from;
83 3 my $want = join "\0", sort @$to;
84 3 my @keys = ([ $foreign->primary_columns ]);
85 3 ▶ if ($foreign->can('unique_constraints')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($foreign->can("unique_constraints")) 3 0 3
86 3 my %uniques = $foreign->unique_constraints;
87 3 push @keys, $uniques{$_} for grep { $_ ne 'primary' } sort keys %uniques;
88 }
89 3 for my $key (@keys) {
90 4 ▶ next unless @$key == @$to && join("\0", sort @$key) eq $want;
Branch: 1 branch
BranchTrueFalseTotal
unless @$key == @$to and join("\0", sort(@$key)) eq $want 1 3 4
Condition66%2/3
@$key == @$to and join("\0", sort(@$key)) eq $want
!ll&&!rl&&r
103
MC/DC50%1/2
@$key == @$to and join("\0", sort(@$key)) eq $want
@$key == @$to join("\0", sort(@$key)) eq $want
Truth table66%2/3
A and B
A= @$key == @$toB= join("\0", sort(@$key)) eq $want
ABresult
0X0
100
111
91 3 return ([ map { $pair{$_} } @$key ], [ @$key ]);
92 }
93 0 return ($from, $to);
94 }
95  
96 # ' ON DELETE CASCADE' for the on_delete / on_update attribute of a belongs_to.
97 # Any case and spacing is taken; NO ACTION (the server's default) and an unset
98 # value write nothing; a word that is no foreign key action throws here
99 # instead of reaching the server as a syntax error; SET DEFAULT throws too.
100 126 ▶sub _fk_action {
Subroutine _fk_action: called CC=6 SCAR=17.9
101 126 my ($source, $rel, $attr, $clause, $value) = @_;
102 # '' is "the database's default" (DBIO::Relationship::Base): as if unset
103 126 ▶ return '' unless defined $value && $value =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and $value =~ /\S/ 106 20 126
Condition100%3/3
defined $value and $value =~ /\S/
!ll&&!rl&&r
104220
MC/DC100%2/2
defined $value and $value =~ /\S/
defined $value $value =~ /\S/
Truth table100%3/3
A and B
A= defined $valueB= $value =~ /\S/
ABresult
0X0
100
111
104 20 (my $action = uc $value) =~ s/^\s+|\s+$//g;
105 20 $action =~ s/[\s_]+/ /g;
106 $source->throw_exception(sprintf
107 "relationship '%s' of %s declares %s => '%s', which is no foreign key action "
108 . "(known: NO ACTION, RESTRICT, CASCADE, SET NULL, SET DEFAULT)",
109 $rel, $source->source_name, $attr, $value)
110 20 ▶ unless $FK_ACTION{$action};
Branch: 1 branch
BranchTrueFalseTotal
unless $FK_ACTION{$action} 2 18 20
111 18 ▶ return '' if $action eq 'NO ACTION';
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "NO ACTION" 2 16 18
112 16 ▶ $source->throw_exception(sprintf
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "SET DEFAULT" 6 10 16
113 "relationship '%s' of %s declares %s => '%s': MySQL and MariaDB accept SET DEFAULT "
114 . "but never run it (the server acts as RESTRICT), so it is refused",
115 $rel, $source->source_name, $attr, $value)
116 if $action eq 'SET DEFAULT';
117 10 return " $clause $action";
118 }
119  
120  
121 236 ▶sub order_by_foreign_keys {
Subroutine order_by_foreign_keys: called CC=10 SCAR=23.1
Pod documented
122 236 my ($tables, $to_of) = @_;
123 236 my %is_ours = map { $_->{name} => 1 } @$tables;
124 236 my (%out, @steps);
125 236 my @todo = @$tables;
126 236 ▶ while (@todo) {
Branch: 1 branch
BranchTrueFalseTotal
if (@todo) 166 236 402
127 my ($pick) = grep {
128 166 my $t = $_;
129 265 ▶ !grep { my $to = $to_of->($_); $to ne $t->{name} && $is_ours{$to} && !$out{$to} } @{ $t->{fks} };
Condition100%6/6
$to ne $t->{'name'} && $is_ours{$to} && !$out{$to}
!ll&&!rl&&r
106572
$to ne $t->{"name"} and $is_ours{$to}
!ll&&!rl&&r
64137
MC/DC100%3/3
$to ne $t->{'name'} && $is_ours{$to} && !$out{$to}
$to ne $t->{"name"} $is_ours{$to} !$out{$to}
Truth table100%4/4
A and B && not(C)
A= $to ne $t->{"name"}B= $is_ours{$to}C= !$out{$to}
ABCresult
0XX0
10X0
1100
1111
130 } @todo;
131 166 ▶ $pick //= _first_in_cycle(\@todo, $to_of, \%is_ours, \%out) // $todo[0];
Condition50%3/6
$pick //= _first_in_cycle(\@todo, $to_of, \%is_ours, \%out) // $todo[0]
l!l&&r!l&&!r
15880
_first_in_cycle(\@todo, $to_of, \%is_ours, \%out) // $todo[0]
l!l&&r!l&&!r
800
MC/DC0%0/3
$pick //= _first_in_cycle(\@todo, $to_of, \%is_ours, \%out) // $todo[0]
$pick _first_in_cycle(\@todo, $to_of, \%is_ours, \%out) $todo[0]
Truth table0%0/4
A //= B // C
A= $pickB= _first_in_cycle(\@todo, $to_of, \%is_ours, \%out)C= $todo[0]
ABCresult
1XX1
01X1
0011
0000
132 166 @todo = grep { $_ != $pick } @todo;
133  
134 166 my (@inline, @held);
135 166 for my $fk (@{ $pick->{fks} }) {
136 69 my $to = $to_of->($fk);
137 69 ▶ push @{ $to ne $pick->{name} && $is_ours{$to} && !$out{$to} ? \@held : \@inline }, $fk;
Branch: 1 branch
BranchTrueFalseTotal
$to ne $pick->{'name'} && $is_ours{$to} && !$out{$to} ? : 8 61 69
Condition100%6/6
$to ne $pick->{"name"} and $is_ours{$to} and not $out{$to}
!ll&&!rl&&r
7548
$to ne $pick->{"name"} and $is_ours{$to}
!ll&&!rl&&r
3462
MC/DC100%3/3
$to ne $pick->{"name"} and $is_ours{$to} and not $out{$to}
$to ne $pick->{"name"} $is_ours{$to} not $out{$to}
Truth table100%4/4
A and B and not(C)
A= $to ne $pick->{"name"}B= $is_ours{$to}C= not $out{$to}
ABCresult
0XX0
10X0
1100
1111
138 }
139 166 $out{ $pick->{name} } = 1;
140 166 push @steps, { table => $pick, inline => \@inline, held => \@held };
141 }
142 236 return @steps;
143 }
144  
145 # Of the tables left, the first that lies on a cycle of the foreign keys still
146 # open. Breaking the cycle at a table that merely waits on one would hold
147 # back its foreign keys for nothing.
148 8 ▶sub _first_in_cycle {
Subroutine _first_in_cycle: called CC=9 SCAR=22.3
149 8 my ($todo, $to_of, $is_ours, $out) = @_;
150 8 my %waits_on;
151 8 for my $t (@$todo) {
152 19 ▶ $waits_on{ $t->{name} } = [ grep { $_ ne $t->{name} && $is_ours->{$_} && !$out->{$_} }
Condition50%3/6
$_ ne $t->{'name'} && $is_ours->{$_} && !$out->{$_}
!ll&&!rl&&r
0217
$_ ne $t->{"name"} and $is_ours->{$_}
!ll&&!rl&&r
0019
MC/DC33%1/3
$_ ne $t->{'name'} && $is_ours->{$_} && !$out->{$_}
$_ ne $t->{"name"} $is_ours->{$_} !$out->{$_}
Truth table50%2/4
A and B && not(C)
A= $_ ne $t->{"name"}B= $is_ours->{$_}C= !$out->{$_}
ABCresult
0XX0
10X0
1100
1111
153 17 map { $to_of->($_) } @{ $t->{fks} } ];
154 }
155 8 for my $t (@$todo) {
156 9 my (%seen, @walk);
157 9 @walk = @{ $waits_on{ $t->{name} } };
158 9 ▶ while (defined(my $n = shift @walk)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $n = shift @walk)) 19 1 20
159 19 ▶ return $t if $n eq $t->{name};
Branch: 1 branch
BranchTrueFalseTotal
if $n eq $t->{"name"} 8 11 19
160 11 ▶ next if $seen{$n}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$n}++ 1 10 11
161 10 ▶ push @walk, @{ $waits_on{$n} // [] };
Condition50%1/2
$waits_on{$n} // []
l!l
100
MC/DC0%0/1
$waits_on{$n} // []
$waits_on{$n}
Truth table50%1/2
A
A= $waits_on{$n}
Aresult
11
00
162 }
163 }
164 0 return;
165 }
166  
167  
168 86 my %CLAUSE_END = map { $_ => 1 } qw(
169 SELECT WHERE GROUP HAVING ORDER LIMIT UNION INTERSECT EXCEPT WINDOW FOR INTO PROCEDURE LOCK
170 );
171  
172 158 ▶sub _view_tokens {
Subroutine _view_tokens: called CC=11 SCAR=24.0
173 158 my ($text) = @_;
174 158 my @tok;
175 158 pos($text) = 0;
176 158 ▶ while (pos($text) < length $text) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $text < length $text) 1891 158 2049
177 1891 ▶ if ($text =~ /\G\s+/gc) { }
Branch: 9 branches
BranchTrueFalseTotal
if ($text =~ /\G\s+/cg) { } 752 1139 1891
elsif ($text =~ m[\G/\*.*?\*/]cgs) { } 1 1138 1139
elsif ($text =~ /\G(?:--(?=\s|\z)|#)[^\n]*/cg) { } 2 1136 1138
elsif ($text =~ /\G`((?:[^`]|``)*)`/cg) { } 331 805 1136
elsif ($text =~ /\G'(?:[^'\\]|\\.|'')*'/cgs) { } 4 801 805
elsif ($text =~ /\G"(?:[^"\\]|\\.|"")*"/cgs) { } 4 797 801
elsif ($text =~ /\G([\w\$]+)/cg) { } 644 153 797
elsif ($text =~ /\G([().,])/cg) { } 133 20 153
elsif ($text =~ /\G./cgs) { } 20 0 20
178 elsif ($text =~ m{\G/\*.*?\*/}gcs) { }
179 elsif ($text =~ /\G(?:--(?=\s|\z)|#)[^\n]*/gc) { }
180 elsif ($text =~ /\G`((?:[^`]|``)*)`/gc) {
181 331 (my $n = $1) =~ s/``/`/g;
182 331 push @tok, [ id => $n ];
183 }
184 4 elsif ($text =~ /\G'(?:[^'\\]|\\.|'')*'/gcs) { push @tok, [ str => '' ] }
185 4 elsif ($text =~ /\G"(?:[^"\\]|\\.|"")*"/gcs) { push @tok, [ str => '' ] }
186 644 elsif ($text =~ /\G([\w\$]+)/gc) { push @tok, [ word => $1 ] }
187 133 elsif ($text =~ /\G([().,])/gc) { push @tok, [ p => $1 ] }
188 20 elsif ($text =~ /\G./gcs) { push @tok, [ other => '' ] }
189 }
190 158 return @tok;
191 }
192  
193 160 ▶sub view_reads {
Subroutine view_reads: called CC=32 SCAR=34.8
Pod documented
194 160 my ($def) = @_;
195 160 ▶ return () unless defined $def && length $def;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $def and length $def 2 158 160
Condition66%2/3
defined $def and length $def
!ll&&!rl&&r
20158
MC/DC50%1/2
defined $def and length $def
defined $def length $def
Truth table66%2/3
A and B
A= defined $defB= length $def
ABresult
0X0
100
111
196 158 my @tok = _view_tokens($def);
197 158 my (@reads, %seen);
198  
199 # One frame per pair of parentheses. expect: the next token stands where a
200 # table is named; from: a comma does the same; select: this frame holds a
201 # SELECT, so its FROM is a table list (a FROM inside TRIM(...) is not).
202 158 my @frames = ({ expect => 0, from => 0, select => 1 });
203 158 my $i = 0;
204 158 ▶ while ($i < @tok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @tok) 1128 158 1286
205 1128 my ($type, $val) = @{ $tok[$i] };
206 1128 my $f = $frames[-1];
207 1128 ▶ if ($type eq 'p' && $val eq '(') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "p" and $val eq "(") 15 1113 1128
Condition100%3/3
$type eq "p" and $val eq "("
!ll&&!rl&&r
99911415
MC/DC100%2/2
$type eq "p" and $val eq "("
$type eq "p" $val eq "("
Truth table100%3/3
A and B
A= $type eq "p"B= $val eq "("
ABresult
0X0
100
111
208 15 push @frames, { expect => $f->{expect}, from => $f->{expect}, select => 0 };
209 15 $f->{expect} = 0;
210 15 $i++;
211 15 next;
212 }
213 1113 ▶ if ($type eq 'p' && $val eq ')') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "p" and $val eq ")") 15 1098 1113
Condition100%3/3
$type eq "p" and $val eq ")"
!ll&&!rl&&r
9999915
MC/DC100%2/2
$type eq "p" and $val eq ")"
$type eq "p" $val eq ")"
Truth table100%3/3
A and B
A= $type eq "p"B= $val eq ")"
ABresult
0X0
100
111
214 15 ▶ pop @frames if @frames > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @frames > 1 15 0 15
215 15 $i++;
216 15 next;
217 }
218 1098 ▶ if ($type eq 'p' && $val eq ',') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "p" and $val eq ",") 19 1079 1098
Condition100%3/3
$type eq "p" and $val eq ","
!ll&&!rl&&r
9998019
MC/DC100%2/2
$type eq "p" and $val eq ","
$type eq "p" $val eq ","
Truth table100%3/3
A and B
A= $type eq "p"B= $val eq ","
ABresult
0X0
100
111
219 19 ▶ $f->{expect} = $f->{from} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$f->{'from'} ? : 4 15 19
220 19 $i++;
221 19 next;
222 }
223 1079 ▶ if ($type eq 'word') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "word") 644 435 1079
224 644 my $kw = uc $val;
225 644 ▶ if ($kw eq 'FROM' && $f->{select}) { @$f{qw(from expect)} = (1, 1); $i++; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "FROM" and $f->{"select"}) 160 484 644
Condition100%3/3
$kw eq "FROM" and $f->{"select"}
!ll&&!rl&&r
4822160
MC/DC100%2/2
$kw eq "FROM" and $f->{"select"}
$kw eq "FROM" $f->{"select"}
Truth table100%3/3
A and B
A= $kw eq "FROM"B= $f->{"select"}
ABresult
0X0
100
111
226 484 ▶ if (($kw eq 'JOIN' || $kw eq 'STRAIGHT_JOIN') && $f->{from}) { $f->{expect} = 1; $i++; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "JOIN" || $kw eq "STRAIGHT_JOIN" and $f->{"from"}) 11 473 484
Condition83%5/6
$kw eq "JOIN" || $kw eq "STRAIGHT_JOIN" and $f->{"from"}
!ll&&!rl&&r
473011
$kw eq "JOIN" or $kw eq "STRAIGHT_JOIN"
l!l&&r!l&&!r
101473
MC/DC66%2/3
$kw eq "JOIN" || $kw eq "STRAIGHT_JOIN" and $f->{"from"}
$kw eq "JOIN" $kw eq "STRAIGHT_JOIN" $f->{"from"}
Truth table60%3/5
A or B and C
A= $kw eq "JOIN"B= $kw eq "STRAIGHT_JOIN"C= $f->{"from"}
ABCresult
00X0
1X00
0100
1X11
0111
227 473 ▶ if ($CLAUSE_END{$kw}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CLAUSE_END{$kw}) 171 302 473
228 171 ▶ $f->{select} = 1 if $kw eq 'SELECT';
Branch: 1 branch
BranchTrueFalseTotal
if $kw eq "SELECT" 162 9 171
229 171 @$f{qw(from expect)} = (0, 0);
230 171 $i++;
231 171 next;
232 }
233 }
234 737 ▶ if ($f->{expect} && ($type eq 'id' || $type eq 'word')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f->{"expect"} and $type eq "id" || $type eq "word") 174 563 737
Condition66%4/6
$f->{"expect"} and $type eq "id" || $type eq "word"
!ll&&!rl&&r
5630174
$type eq "id" or $type eq "word"
l!l&&r!l&&!r
99750
MC/DC33%1/3
$f->{"expect"} and $type eq "id" || $type eq "word"
$f->{"expect"} $type eq "id" $type eq "word"
Truth table75%3/4
A and B or C
A= $f->{"expect"}B= $type eq "id"C= $type eq "word"
ABCresult
0XX0
1000
11X1
1011
235 # a (possibly qualified) name; the last part is the table
236 174 my $name = $val;
237 174 $i++;
238 174 ▶ while ($i + 1 < @tok && $tok[$i][0] eq 'p' && $tok[$i][1] eq '.' && ($tok[$i + 1][0] eq 'id' || $tok[$i + 1][0] eq 'word')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i + 1 < @tok and $tok[$i][0] eq "p" and $tok[$i][1] eq "." and $tok[$i + 1][0] eq "id" || $tok[$i + 1][0] eq "word") 4 174 178
Condition75%9/12
$i + 1 < @tok and $tok[$i][0] eq "p" and $tok[$i][1] eq "." and $tok[$i + 1][0] eq "id" || $tok[$i + 1][0] eq "word"
!ll&&!rl&&r
17404
$i + 1 < @tok and $tok[$i][0] eq "p" and $tok[$i][1] eq "."
!ll&&!rl&&r
17044
$i + 1 < @tok and $tok[$i][0] eq "p"
!ll&&!rl&&r
137338
$tok[$i + 1][0] eq "id" or $tok[$i + 1][0] eq "word"
l!l&&r!l&&!r
400
MC/DC60%3/5
$i + 1 < @tok and $tok[$i][0] eq "p" and $tok[$i][1] eq "." and $tok[$i + 1][0] eq "id" || $tok[$i + 1][0] eq "word"
$i + 1 < @tok $tok[$i][0] eq "p" $tok[$i][1] eq "." $tok[$i + 1][0] eq "id" $tok[$i + 1][0] eq "word"
Truth table66%4/6
A and B and C and D or E
A= $i + 1 < @tokB= $tok[$i][0] eq "p"C= $tok[$i][1] eq "."D= $tok[$i + 1][0] eq "id"E= $tok[$i + 1][0] eq "word"
ABCDEresult
0XXXX0
10XXX0
110XX0
111000
1111X1
111011
239 4 $name = $tok[$i + 1][1];
240 4 $i += 2;
241 }
242 174 ▶ my $call = $i < @tok && $tok[$i][0] eq 'p' && $tok[$i][1] eq '(';
Condition100%6/6
$i < @tok && $tok[$i][0] eq 'p' && $tok[$i][1] eq '('
!ll&&!rl&&r
16851
$i < @tok and $tok[$i][0] eq "p"
!ll&&!rl&&r
135336
MC/DC100%3/3
$i < @tok && $tok[$i][0] eq 'p' && $tok[$i][1] eq '('
$i < @tok $tok[$i][0] eq "p" $tok[$i][1] eq '('
Truth table100%4/4
A and B && C
A= $i < @tokB= $tok[$i][0] eq "p"C= $tok[$i][1] eq '('
ABCresult
0XX0
10X0
1100
1111
243 174 ▶ push @reads, $name unless $call || $seen{$name}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $call or $seen{$name}++ 173 1 174
Condition66%2/3
$call or $seen{$name}++
l!l&&r!l&&!r
10173
MC/DC50%1/2
$call or $seen{$name}++
$call $seen{$name}++
Truth table66%2/3
A or B
A= $callB= $seen{$name}++
ABresult
1X1
011
000
244 174 $f->{expect} = 0;
245 174 next;
246 }
247 563 $f->{expect} = 0;
248 563 $i++;
249 }
250 158 return @reads;
251 }
252  
253  
254 421 ▶sub order_views {
Subroutine order_views: called CC=14 SCAR=26.4
Pod documented
255 421 my ($defs) = @_;
256 421 my @names = sort keys %$defs;
257 421 my %by_fold;
258 421 push @{ $by_fold{ lc $_ } }, $_ for @names;
259  
260 421 my %reads;
261 421 for my $v (@names) {
262 122 my %dep;
263 122 for my $r (view_reads($defs->{$v})) {
264 my $to = exists $defs->{$r} ? $r
265 124 ▶ : (@{ $by_fold{ lc $r } // [] } == 1 ? $by_fold{ lc $r }[0] : undef);
Branch: 2 branches
BranchTrueFalseTotal
exists $defs->{$r} ? : 68 56 124
@{$by_fold{lc $r} // [];} == 1 ? : 1 55 56
Condition100%2/2
$by_fold{lc $r} // []
l!l
155
MC/DC100%1/1
$by_fold{lc $r} // []
$by_fold{lc $r}
Truth table100%2/2
A
A= $by_fold{lc $r}
Aresult
11
00
266 124 ▶ $dep{$to} = 1 if defined $to && $to ne $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $to and $to ne $v 68 56 124
Condition100%3/3
defined $to and $to ne $v
!ll&&!rl&&r
55168
MC/DC100%2/2
defined $to and $to ne $v
defined $to $to ne $v
Truth table100%3/3
A and B
A= defined $toB= $to ne $v
ABresult
0X0
100
111
267 }
268 122 $reads{$v} = [ sort keys %dep ];
269 }
270  
271 421 my (%out, @order);
272 421 my @todo = @names;
273 421 ▶ while (@todo) {
Branch: 1 branch
BranchTrueFalseTotal
if (@todo) 116 418 534
274 116 my ($pick) = grep { my $v = $_; !grep { !$out{$_} } @{ $reads{$v} } } @todo;
275 116 ▶ unless (defined $pick) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pick) 3 113 116
276 my @cycle = grep {
277 3 my $v = $_;
278 9 my (%seen, @walk);
279 9 @walk = @{ $reads{$v} };
280 9 my $found;
281 9 ▶ while (defined(my $n = shift @walk)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $n = shift @walk)) 27 0 27
282 27 ▶ if ($n eq $v) { $found = 1; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq $v) 9 18 27
283 18 ▶ next if $seen{$n}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$n}++ 0 18 18
284 18 push @walk, @{ $reads{$n} };
285 }
286 9 $found;
287 } @todo;
288 DBIO::Exception->throw(sprintf
289 'DBIO::MySQL::DDL: the views %s read each other in a cycle (%s), no order creates them',
290 9 join(', ', map { quote_ident($_) } @cycle),
291 3 join('; ', map { my $v = $_; sprintf '%s reads %s', quote_ident($v),
292 9 join(', ', map { quote_ident($_) } grep { my $r = $_; grep { $_ eq $r } @cycle } @{ $reads{$v} }) } @cycle));
293 }
294 113 @todo = grep { $_ ne $pick } @todo;
295 113 $out{$pick} = 1;
296 113 push @order, $pick;
297 }
298 418 return @order;
299 }
300  
301  
302  
303  
304 5 ▶sub qualified_tables {
Subroutine qualified_tables: called CC=8 SCAR=21.1
Pod documented
305 5 my ($class, $schema) = @_;
306 5 my (@out, %seen);
307 5 for my $source_name (sort $schema->sources) {
308 13 my $source = $schema->source($source_name);
309 13 ▶ next if $source->isa('DBIO::ResultSource::View');
Branch: 1 branch
BranchTrueFalseTotal
if $source->isa("DBIO::ResultSource::View") 6 7 13
310 7 my $name = $source->name;
311 7 ▶ $name = $$name if ref $name eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref $name eq "SCALAR" 1 6 7
312 7 ▶ next if ref $name || $name =~ /\s|\(/;
Branch: 1 branch
BranchTrueFalseTotal
if ref $name or $name =~ /\s|\(/ 0 7 7
Condition33%1/3
ref $name or $name =~ /\s|\(/
l!l&&r!l&&!r
007
MC/DC0%0/2
ref $name or $name =~ /\s|\(/
ref $name $name =~ /\s|\(/
Truth table33%1/3
A or B
A= ref $nameB= $name =~ /\s|\(/
ABresult
1X1
011
000
313 7 my ($database) = split_table_name($name);
314 7 ▶ push @out, [ $name, $database ] if defined $database && !$seen{$name}++;
Branch: 1 branch
BranchTrueFalseTotal
if defined $database and not $seen{$name}++ 2 5 7
Condition66%2/3
defined $database and not $seen{$name}++
!ll&&!rl&&r
502
MC/DC50%1/2
defined $database and not $seen{$name}++
defined $database not $seen{$name}++
Truth table66%2/3
A and not(B)
A= defined $databaseB= not $seen{$name}++
ABresult
0X0
100
111
315 }
316 5 return @out;
317 }
318  
319 4 ▶sub drop_ddl {
Subroutine drop_ddl: called CC=13 SCAR=27.2
Pod documented
320 4 my ($class, $schema) = @_;
321  
322 4 my (%view_def, @tables, %seen);
323 4 for my $source_name (sort $schema->sources) {
324 12 my $source = $schema->source($source_name);
325 12 my $name = $source->name;
326 12 ▶ if ($source->isa('DBIO::ResultSource::View')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source->isa("DBIO::ResultSource::View")) 6 6 12
327 6 ▶ next if $source->can('is_virtual') && $source->is_virtual;
Branch: 1 branch
BranchTrueFalseTotal
if $source->can("is_virtual") and $source->is_virtual 2 4 6
Condition66%2/3
$source->can("is_virtual") and $source->is_virtual
!ll&&!rl&&r
042
MC/DC50%1/2
$source->can("is_virtual") and $source->is_virtual
$source->can("is_virtual") $source->is_virtual
Truth table66%2/3
A and B
A= $source->can("is_virtual")B= $source->is_virtual
ABresult
0X0
100
111
328 4 ▶ next if ref $name;
Branch: 1 branch
BranchTrueFalseTotal
if ref $name 0 4 4
329 4 ▶ my $def = $source->can('view_definition') ? $source->view_definition : undef;
Branch: 1 branch
BranchTrueFalseTotal
$source->can('view_definition') ? : 4 0 4
330 4 ▶ next unless defined $def && length $def;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $def and length $def 0 4 4
Condition33%1/3
defined $def and length $def
!ll&&!rl&&r
004
MC/DC0%0/2
defined $def and length $def
defined $def length $def
Truth table33%1/3
A and B
A= defined $defB= length $def
ABresult
0X0
100
111
331 4 $view_def{$name} = $def;
332 4 next;
333 }
334 6 ▶ $name = $$name if ref $name eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref $name eq "SCALAR" 1 5 6
335 6 ▶ next if ref $name || $name =~ /\s|\(/;
Branch: 1 branch
BranchTrueFalseTotal
if ref $name or $name =~ /\s|\(/ 0 6 6
Condition33%1/3
ref $name or $name =~ /\s|\(/
l!l&&r!l&&!r
006
MC/DC0%0/2
ref $name or $name =~ /\s|\(/
ref $name $name =~ /\s|\(/
Truth table33%1/3
A or B
A= ref $nameB= $name =~ /\s|\(/
ABresult
1X1
011
000
336 6 ▶ push @tables, $name unless $seen{$name}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{$name}++ 6 0 6
337 }
338  
339 return join "\n\n",
340 4 (map { sprintf 'DROP VIEW IF EXISTS %s;', quote_ident($_) } reverse order_views(\%view_def)),
341 4 (map { sprintf 'DROP TABLE IF EXISTS %s;', quote_table($_) } @tables);
342 }
343  
344  
345 87 ▶sub install_ddl {
Subroutine install_ddl: called CC=81 SCAR=46.2
Pod documented
346 87 my ($class, $schema, $opts) = @_;
347 87 ▶ $opts ||= {};
Condition100%2/2
$opts ||= {}
l!l
384
MC/DC100%1/1
$opts ||= {}
$opts
Truth table100%2/2
A
A= $opts
Aresult
11
00
348  
349 87 my %view_def; # view name => definition, created in dependency order below
350 my @tables; # one entry per CREATE TABLE, in source-name order
351 87 my %seen_table;
352 87 my %seen_view;
353  
354 87 for my $source_name (sort $schema->sources) {
355 187 my $source = $schema->source($source_name);
356 187 my $result_class = $source->result_class;
357 187 my $table_name = $source->name;
358  
359 # Views: emit CREATE VIEW after all tables; skip virtual views.
360 187 ▶ if ($source->isa('DBIO::ResultSource::View')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source->isa("DBIO::ResultSource::View")) 36 151 187
361 36 ▶ next if $source->can('is_virtual') && $source->is_virtual;
Branch: 1 branch
BranchTrueFalseTotal
if $source->can("is_virtual") and $source->is_virtual 3 33 36
Condition66%2/3
$source->can("is_virtual") and $source->is_virtual
!ll&&!rl&&r
0333
MC/DC50%1/2
$source->can("is_virtual") and $source->is_virtual
$source->can("is_virtual") $source->is_virtual
Truth table66%2/3
A and B
A= $source->can("is_virtual")B= $source->is_virtual
ABresult
0X0
100
111
362 33 ▶ my $vname = ref $table_name eq 'SCALAR' ? $$table_name : $table_name;
Branch: 1 branch
BranchTrueFalseTotal
ref $table_name eq 'SCALAR' ? : 0 33 33
363 33 ▶ next if ref $vname || $seen_view{$vname}++;
Branch: 1 branch
BranchTrueFalseTotal
if ref $vname or $seen_view{$vname}++ 0 33 33
Condition33%1/3
ref $vname or $seen_view{$vname}++
l!l&&r!l&&!r
0033
MC/DC0%0/2
ref $vname or $seen_view{$vname}++
ref $vname $seen_view{$vname}++
Truth table33%1/3
A or B
A= ref $vnameB= $seen_view{$vname}++
ABresult
1X1
011
000
364 33 check_table_name($vname, 'view');
365 32 ▶ next if defined $opts->{database};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"database"} 0 32 32
366 32 ▶ my $def = $source->can('view_definition') ? $source->view_definition : undef;
Branch: 1 branch
BranchTrueFalseTotal
$source->can('view_definition') ? : 32 0 32
367 32 ▶ next unless defined $def && length $def;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $def and length $def 0 32 32
Condition33%1/3
defined $def and length $def
!ll&&!rl&&r
0032
MC/DC0%0/2
defined $def and length $def
defined $def length $def
Truth table33%1/3
A and B
A= defined $defB= length $def
ABresult
0X0
100
111
368 32 $view_def{$vname} = $def;
369 32 next;
370 }
371  
372 # A scalar-ref name is either a literal table name (\'cd') or an inline
373 # subquery source; deref the former, skip the latter. The literal name is
374 # quoted like any other: it is one identifier here.
375 151 ▶ if (ref $table_name eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $table_name eq "SCALAR") 2 149 151
376 2 $table_name = $$table_name;
377 2 ▶ next if $table_name =~ /\s|\(/;
Branch: 1 branch
BranchTrueFalseTotal
if $table_name =~ /\s|\(/ 0 2 2
378 }
379 151 ▶ next if ref $table_name;
Branch: 1 branch
BranchTrueFalseTotal
if ref $table_name 0 151 151
380 151 check_table_name($table_name);
381  
382 # A table of another database is made there, and only by the install of
383 # the schema itself: the temporary database of a diff leaves it out
384 # (local_only), or a temporary database for one database alone (database).
385 148 my ($table_database, $local_name) = split_table_name($table_name);
386 148 ▶ next if defined $table_database && $opts->{local_only};
Branch: 1 branch
BranchTrueFalseTotal
if defined $table_database and $opts->{"local_only"} 2 146 148
Condition100%3/3
defined $table_database and $opts->{"local_only"}
!ll&&!rl&&r
14242
MC/DC100%2/2
defined $table_database and $opts->{"local_only"}
defined $table_database $opts->{"local_only"}
Truth table100%3/3
A and B
A= defined $table_databaseB= $opts->{"local_only"}
ABresult
0X0
100
111
387  
388 # The temporary database of one other database (karr k122) gets that
389 # database's tables, under the names they have there.
390 146 ▶ if (defined $opts->{database}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{"database"}) 3 143 146
391 3 ▶ next unless defined $table_database && $table_database eq $opts->{database};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $table_database and $table_database eq $opts->{"database"} 2 1 3
Condition100%3/3
defined $table_database and $table_database eq $opts->{"database"}
!ll&&!rl&&r
111
MC/DC100%2/2
defined $table_database and $table_database eq $opts->{"database"}
defined $table_database $table_database eq $opts->{"database"}
Truth table100%3/3
A and B
A= defined $table_databaseB= $table_database eq $opts->{"database"}
ABresult
0X0
100
111
392 1 $table_name = $local_name;
393 }
394  
395 # Several result sources can map to one physical table; emit it once.
396 144 ▶ next if $seen_table{$table_name}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_table{$table_name}++ 0 144 144
397  
398 144 my @col_defs;
399 my @fks; # foreign keys as foreign_key_names takes them (actions as ' ON DELETE ...' clauses)
400 144 my @pk_cols = $source->primary_columns;
401  
402 144 for my $col_name ($source->columns) {
403 294 my $info = $source->column_info($col_name);
404 294 my $type = _mysql_column_type($info);
405  
406 293 my $def = sprintf ' %s %s', quote_ident($col_name), $type;
407 293 ▶ $def .= ' NOT NULL' if !$info->{is_nullable};
Branch: 1 branch
BranchTrueFalseTotal
unless $info->{"is_nullable"} 213 80 293
408 # AUTO_INCREMENT is for integers: on the string a GUID is stored as the
409 # server refuses the table (1063), so the attribute is not written there
410 # (karr k115). The value of such a column is generated by the storage.
411 $def .= ' AUTO_INCREMENT'
412 293 ▶ if $info->{is_auto_increment} && lc($info->{data_type} // '') ne 'uniqueidentifier';
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"is_auto_increment"} and lc($info->{"data_type"} // "") ne "uniqueidentifier" 85 208 293
Condition80%4/5
$info->{"is_auto_increment"} and lc($info->{"data_type"} // "") ne "uniqueidentifier"
!ll&&!rl&&r
207185
$info->{"data_type"} // ""
l!l
860
MC/DC50%1/2
$info->{"is_auto_increment"} and lc($info->{"data_type"} // "") ne "uniqueidentifier"
$info->{"is_auto_increment"} $info->{"data_type"}
Truth table66%2/3
A and B
A= $info->{"is_auto_increment"}B= $info->{"data_type"}
ABresult
0X0
100
111
413  
414 293 ▶ if (defined $info->{default_value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"default_value"}) 5 288 293
415 5 $def .= " DEFAULT " . default_sql($info->{default_value});
416 }
417  
418 293 push @col_defs, $def;
419 }
420  
421 143 ▶ if (@pk_cols) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pk_cols) 143 0 143
422 push @col_defs, sprintf ' PRIMARY KEY (%s)',
423 143 join(', ', map { quote_ident($_) } @pk_cols);
424 }
425  
426 # Unique constraints
427 143 ▶ if ($source->can('unique_constraints')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source->can("unique_constraints")) 143 0 143
428 143 my %uniques = $source->unique_constraints;
429 143 for my $uname (sort keys %uniques) {
430 153 ▶ next if $uname eq 'primary';
Branch: 1 branch
BranchTrueFalseTotal
if $uname eq "primary" 143 10 153
431 10 my $cols = $uniques{$uname};
432 push @col_defs, sprintf ' UNIQUE KEY %s (%s)',
433 quote_ident($uname),
434 10 join(', ', map { quote_ident($_) } @$cols);
435 }
436 }
437  
438 # Foreign keys derived from belongs_to relationships
439 143 for my $rel ($source->relationships) {
440 68 my $info = $source->relationship_info($rel);
441 68 ▶ next unless $info && $info->{attrs} && $info->{attrs}{is_foreign_key_constraint};
Branch: 1 branch
BranchTrueFalseTotal
unless $info and $info->{"attrs"} and $info->{"attrs"}{"is_foreign_key_constraint"} 0 68 68
Condition33%2/6
$info and $info->{"attrs"} and $info->{"attrs"}{"is_foreign_key_constraint"}
!ll&&!rl&&r
0068
$info and $info->{"attrs"}
!ll&&!rl&&r
0068
MC/DC0%0/3
$info and $info->{"attrs"} and $info->{"attrs"}{"is_foreign_key_constraint"}
$info $info->{"attrs"} $info->{"attrs"}{"is_foreign_key_constraint"}
Truth table25%1/4
A and B and C
A= $infoB= $info->{"attrs"}C= $info->{"attrs"}{"is_foreign_key_constraint"}
ABCresult
0XX0
10X0
1100
1111
442  
443 68 my $foreign = $info->{class};
444 68 my $foreign_source = eval { $schema->source($foreign) }
445 0 ▶ // eval { $schema->source($foreign =~ s/.*:://r) };
Condition33%1/3
eval { do { $schema->source($foreign) } } // eval { do { $schema->source($foreign =~ s/.*:://r) } }
l!l&&r!l&&!r
6800
MC/DC0%0/2
eval { do { $schema->source($foreign) } } // eval { do { $schema->source($foreign =~ s/.*:://r) } }
eval { do { $schema->source($foreign) } } eval { do { $schema->source($foreign =~ s/.*:://r) } }
Truth table33%1/3
A // B
A= eval { do { $schema->source($foreign) } }B= eval { do { $schema->source($foreign =~ s/.*:://r) } }
ABresult
1X1
011
000
446 68 ▶ next unless $foreign_source;
Branch: 1 branch
BranchTrueFalseTotal
unless $foreign_source 0 68 68
447  
448 # Neither server lets a foreign key reference a view (1824): the
449 # relationship stays, the key is left out (karr k118).
450 68 ▶ next if $foreign_source->isa('DBIO::ResultSource::View');
Branch: 1 branch
BranchTrueFalseTotal
if $foreign_source->isa("DBIO::ResultSource::View") 2 66 68
451  
452 66 my $cond = $info->{cond};
453 66 ▶ next unless ref $cond eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cond eq "HASH" 0 66 66
454  
455 66 my (@from, @to);
456 66 for my $foreign_col (sort keys %$cond) {
457 69 my $fcol = $foreign_col;
458 69 $fcol =~ s/^foreign\.//;
459 69 my $self_col = $cond->{$foreign_col};
460 69 $self_col =~ s/^self\.//;
461 69 push @to, $fcol;
462 69 push @from, $self_col;
463 }
464 66 my ($ordered_from, $ordered_to) = _order_by_target_key($foreign_source, \@from, \@to);
465 66 @from = @$ordered_from;
466 66 @to = @$ordered_to;
467  
468 # A literal table name (\'cd') arrives as a scalar ref; deref it so
469 # the FK references the table, not "SCALAR(0x...)".
470 66 my $foreign_name = $foreign_source->name;
471 66 ▶ $foreign_name = $$foreign_name if ref $foreign_name eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref $foreign_name eq "SCALAR" 0 66 66
472  
473 # A key between a table of another database and anything else is not
474 # written, and not left out silently either (karr k120).
475 66 ▶ if (!ref $foreign_name && (defined $table_database || defined +(split_table_name($foreign_name))[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $foreign_name and defined $table_database || defined((split_table_name($foreign_name))[0])) 1 65 66
Condition66%4/6
not ref $foreign_name and defined $table_database || defined((split_table_name($foreign_name))[0])
!ll&&!rl&&r
0651
defined $table_database or defined((split_table_name($foreign_name))[0])
l!l&&r!l&&!r
0165
MC/DC33%1/3
not ref $foreign_name and defined $table_database || defined((split_table_name($foreign_name))[0])
not ref $foreign_name defined $table_database defined((split_table_name($foreign_name))[0])
Truth table50%2/4
not(A) and B or C
A= not ref $foreign_nameB= defined $table_databaseC= defined((split_table_name($foreign_name))[0])
ABCresult
0XX0
1000
11X1
1011
476 1 DBIO::Exception->throw(sprintf
477 "DBIO::MySQL: the foreign key of %s to %s is refused: a table in "
478 . "another database (database.table) takes part in it, and keys "
479 . "across databases are not supported", $table_name, $foreign_name);
480 }
481  
482 # ON UPDATE before ON DELETE, as the diff path writes them (Diff::ForeignKey).
483 65 my $on_update = _fk_action($source, $rel, 'on_update', 'ON UPDATE', $info->{attrs}{on_update});
484 61 my $on_delete = _fk_action($source, $rel, 'on_delete', 'ON DELETE', $info->{attrs}{on_delete});
485  
486 # Named below, once every table is known (foreign_key_names): the fixed
487 # name is the one the diff writes as well, the server's own
488 # (<table>_ibfk_N) goes by the position in the CREATE TABLE and differs
489 # between an install and an upgrade.
490 57 push @fks, {
491 table => $table_name, from_columns => \@from, to_table => $foreign_name,
492 to_columns => \@to, on_update => $on_update, on_delete => $on_delete,
493 };
494 }
495  
496 134 ▶ my $engine = ($result_class->can('mysql_engine') && $result_class->mysql_engine) || 'InnoDB';
Condition60%3/5
$result_class->can('mysql_engine') && $result_class->mysql_engine || 'InnoDB'
l!l
0134
$result_class->can("mysql_engine") and $result_class->mysql_engine
!ll&&!rl&&r
241100
MC/DC0%0/2
$result_class->can('mysql_engine') && $result_class->mysql_engine || 'InnoDB'
$result_class->can("mysql_engine") $result_class->mysql_engine
Truth table66%2/3
A and B
A= $result_class->can("mysql_engine")B= $result_class->mysql_engine
ABresult
111
0X0
100
497 134 ▶ my $charset = ($result_class->can('mysql_charset') && $result_class->mysql_charset) || default_charset();
Condition50%3/6
$result_class->can('mysql_charset') && $result_class->mysql_charset || default_charset()
l!l&&r!l&&!r
01340
$result_class->can("mysql_charset") and $result_class->mysql_charset
!ll&&!rl&&r
241100
MC/DC0%0/3
$result_class->can('mysql_charset') && $result_class->mysql_charset || default_charset()
$result_class->can("mysql_charset") $result_class->mysql_charset default_charset()
Truth table40%2/5
A and B || C
A= $result_class->can("mysql_charset")B= $result_class->mysql_charsetC= default_charset()
ABCresult
11X1
0X11
1011
0X00
1000
498 134 ▶ my $collate = ($result_class->can('mysql_collate') && $result_class->mysql_collate) || default_collation();
Condition50%3/6
$result_class->can('mysql_collate') && $result_class->mysql_collate || default_collation()
l!l&&r!l&&!r
01340
$result_class->can("mysql_collate") and $result_class->mysql_collate
!ll&&!rl&&r
241100
MC/DC0%0/3
$result_class->can('mysql_collate') && $result_class->mysql_collate || default_collation()
$result_class->can("mysql_collate") $result_class->mysql_collate default_collation()
Truth table40%2/5
A and B || C
A= $result_class->can("mysql_collate")B= $result_class->mysql_collateC= default_collation()
ABCresult
11X1
0X11
1011
0X00
1000
499  
500 134 my @index_stmts;
501 134 my $entry = {
502 name => $table_name, col_defs => \@col_defs, fks => \@fks,
503 tail => sprintf(') ENGINE=%s DEFAULT CHARSET=%s COLLATE=%s;', $engine, $charset, $collate),
504 index_stmts => \@index_stmts,
505 };
506 134 push @tables, $entry;
507  
508 # MySQL-specific indexes via mysql_indexes (parallel to pg_indexes)
509 # plus the canonical declaration on the result source (idx / indices,
510 # ADR 0061): its own mysql block carries `using`; a foreign-only entry or
511 # an unknown key in the block is refused by index_declarations_for. On the
512 # same name the canonical declaration wins over the hand-written one.
513 {
514 134 my $indexes = $result_class->can('mysql_indexes')
515 134 ▶ ? { %{ $result_class->mysql_indexes } } : {};
Branch: 1 branch
BranchTrueFalseTotal
$result_class->can('mysql_indexes') ? : 110 24 134
516 134 for my $decl ($source->index_declarations_for('mysql', ['using'])) {
517 7 ▶ my $own = $decl->{driver} && $decl->{driver}{mysql} || {};
Condition80%4/5
$decl->{'driver'} && $decl->{'driver'}{'mysql'} || {}
l!l
25
$decl->{"driver"} and $decl->{"driver"}{"mysql"}
!ll&&!rl&&r
052
MC/DC50%1/2
$decl->{'driver'} && $decl->{'driver'}{'mysql'} || {}
$decl->{"driver"} $decl->{"driver"}{"mysql"}
Truth table66%2/3
A and B
A= $decl->{"driver"}B= $decl->{"driver"}{"mysql"}
ABresult
111
0X0
100
518 $indexes->{ $decl->{name} } = {
519 columns => $decl->{columns},
520 unique => $decl->{unique},
521 7 ▶ (defined $own->{using} ? (using => $own->{using}) : ()),
Branch: 1 branch
BranchTrueFalseTotal
defined $own->{'using'} ? : 2 5 7
522 };
523 }
524 # The server takes an AUTO_INCREMENT column only as a key of the table at
525 # CREATE TABLE time (1075 otherwise), so the first index that starts with
526 # such a column outside the primary key stands in the CREATE TABLE, as the
527 # diff writes it (karr k112, k107). A unique constraint over it is that
528 # key already.
529 6 my %auto_key = map { $_ => 1 }
530 132 grep { $source->column_info($_)->{is_auto_increment} } grep { my $c = $_; !grep { $_ eq $c } @pk_cols } $source->columns;
531 132 ▶ if ($source->can('unique_constraints')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source->can("unique_constraints")) 132 0 132
532 132 my %uniques = $source->unique_constraints;
533 132 ▶ delete $auto_key{ $_->[0] } for grep { $_ && @$_ } map { $uniques{$_} } grep { $_ ne 'primary' } keys %uniques;
Condition33%1/3
$_ && @$_
!ll&&!rl&&r
0010
MC/DC0%0/2
$_ && @$_
$_ @$_
Truth table33%1/3
A && B
A= $_B= @$_
ABresult
0X0
100
111
534 }
535 132 my %dup_of_unique;
536 132 ▶ if ($source->can('unique_constraints')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source->can("unique_constraints")) 132 0 132
537 132 my %uniques = $source->unique_constraints;
538 10 $dup_of_unique{ join "\x1f", @{ $uniques{$_} } } = 1
539 132 ▶ for grep { $_ ne 'primary' && ref $uniques{$_} eq 'ARRAY' && @{ $uniques{$_} } } keys %uniques;
Condition66%4/6
$_ ne 'primary' && ref $uniques{$_} eq 'ARRAY' && @{$uniques{$_};}
!ll&&!rl&&r
132010
$_ ne "primary" and ref $uniques{$_} eq "ARRAY"
!ll&&!rl&&r
132010
MC/DC33%1/3
$_ ne 'primary' && ref $uniques{$_} eq 'ARRAY' && @{$uniques{$_};}
$_ ne "primary" ref $uniques{$_} eq "ARRAY" @{$uniques{$_};}
Truth table50%2/4
A and B && C
A= $_ ne "primary"B= ref $uniques{$_} eq "ARRAY"C= @{$uniques{$_};}
ABCresult
0XX0
10X0
1100
1111
540 }
541 132 for my $idx_name (sort keys %$indexes) {
542 35 my $idx = $indexes->{$idx_name};
543 35 ▶ my $unique = $idx->{unique} ? 'UNIQUE ' : '';
Branch: 1 branch
BranchTrueFalseTotal
$idx->{'unique'} ? : 9 26 35
544  
545 # `using` names two different things in MySQL's CREATE INDEX grammar:
546 # BTREE/HASH are index TYPES (trailing USING clause), FULLTEXT/SPATIAL
547 # are index CLASSES (in front of INDEX). The split itself lives in
548 # DBIO::MySQL::IndexType -- the single source of truth shared with the
549 # migration-diff renderer (karr k52). Here we add the two schema-side
550 # refusals the diff side does not need: an unrecognised `using` value
551 # (RTREE included, which the server only ever picks itself for a SPATIAL
552 # index and never accepts by name, karr k50), and the UNIQUE/class
553 # collision.
554 35 my $class_kw = '';
555 35 my $type = '';
556 35 ▶ if (my $using = $idx->{using}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $using = $idx->{"using"}) 16 19 35
557 16 ($class_kw, $type) = DBIO::MySQL::IndexType::index_type_split($using);
558  
559 16 ▶ croak "mysql_index '$idx_name': invalid using value '$using' -- "
Branch: 1 branch
BranchTrueFalseTotal
unless defined $class_kw 1 15 16
560 . 'MySQL accepts BTREE and HASH (rendered as a USING clause) '
561 . 'and FULLTEXT and SPATIAL (rendered as the index class, '
562 . 'CREATE FULLTEXT/SPATIAL INDEX)'
563 unless defined $class_kw;
564  
565 # UNIQUE, FULLTEXT and SPATIAL share one grammar position in
566 # CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX -- at most one may
567 # appear. `unique => 1` here would concatenate the UNIQUE prefix
568 # with the class keyword into `CREATE UNIQUE FULLTEXT INDEX ...`,
569 # which no MySQL or MariaDB server accepts (karr k52). BTREE/HASH
570 # are index types, a different position, so unique stays valid there.
571 15 ▶ if (length $class_kw && $idx->{unique}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $class_kw and $idx->{"unique"}) 2 13 15
Condition100%3/3
length $class_kw and $idx->{"unique"}
!ll&&!rl&&r
852
MC/DC100%2/2
length $class_kw and $idx->{"unique"}
length $class_kw $idx->{"unique"}
Truth table100%3/3
A and B
A= length $class_kwB= $idx->{"unique"}
ABresult
0X0
100
111
572 2 (my $kw = $class_kw) =~ s/\s+\z//;
573 2 croak "mysql_index '$idx_name': unique cannot be combined with "
574 . "$kw -- UNIQUE, FULLTEXT and SPATIAL share one grammar position "
575 . 'in CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX, so at most one '
576 . 'may appear';
577 }
578 }
579  
580 # An index over exactly the columns of a unique constraint of the
581 # table, in the same order, is a second index for the lookups the
582 # UNIQUE key serves already, and is not written (karr k120). A
583 # FULLTEXT or SPATIAL index is another kind of object.
584 32 ▶ next if !length $class_kw && $dup_of_unique{ join "\x1f", @{ $idx->{columns} // [] } };
Branch: 1 branch
BranchTrueFalseTotal
if not length $class_kw and $dup_of_unique{join "\37", @{$idx->{"columns"} // [];}} 1 31 32
Condition80%4/5
not length $class_kw and $dup_of_unique{join "\37", @{$idx->{"columns"} // [];}}
!ll&&!rl&&r
5261
$idx->{"columns"} // []
l!l
270
MC/DC100%2/2
not length $class_kw and $dup_of_unique{join "\37", @{$idx->{"columns"} // [];}}
not length $class_kw $dup_of_unique{join "\37", @{$idx->{"columns"} // [];}}
MC/DC0%0/1
$idx->{"columns"} // []
$idx->{"columns"}
Truth table100%3/3
not(A) and B
A= not length $class_kwB= $dup_of_unique{join "\37", @{$idx->{"columns"} // [];}}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $idx->{"columns"}
Aresult
11
00
585  
586 my $cols = join ', ',
587 31 ▶ map { quote_ident($_) } @{ $idx->{columns} // [] };
Condition50%1/2
$idx->{"columns"} // []
l!l
310
MC/DC0%0/1
$idx->{"columns"} // []
$idx->{"columns"}
Truth table50%1/2
A
A= $idx->{"columns"}
Aresult
11
00
588 31 ▶ my ($first) = @{ $idx->{columns} // [] };
Condition50%1/2
$idx->{"columns"} // []
l!l
310
MC/DC0%0/1
$idx->{"columns"} // []
$idx->{"columns"}
Truth table50%1/2
A
A= $idx->{"columns"}
Aresult
11
00
589 31 ▶ if (!length $class_kw && defined $first && delete $auto_key{$first}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not length $class_kw and defined $first and delete $auto_key{$first}) 5 26 31
Condition83%5/6
not length $class_kw and defined $first and delete $auto_key{$first}
!ll&&!rl&&r
5215
not length $class_kw and defined $first
!ll&&!rl&&r
5026
MC/DC66%2/3
not length $class_kw and defined $first and delete $auto_key{$first}
not length $class_kw defined $first delete $auto_key{$first}
Truth table75%3/4
not(A) and B and C
A= not length $class_kwB= defined $firstC= delete $auto_key{$first}
ABCresult
0XX0
10X0
1100
1111
590 5 push @col_defs, sprintf ' %sKEY %s (%s)%s', $unique, quote_ident($idx_name), $cols, $type;
591 5 next;
592 }
593 26 push @index_stmts, sprintf 'CREATE %s%sINDEX %s ON %s (%s)%s;',
594 $unique, $class_kw, quote_ident($idx_name), quote_table($table_name),
595 $cols, $type;
596 }
597 }
598 }
599  
600 # The foreign keys get their names, all of them at once; an identical one is
601 # written once.
602 {
603 68 my @all = map { @{ $_->{fks} } } @tables;
604 68 my @names = foreign_key_names(@all);
605 68 my %by_ref; @by_ref{ map { "$_" } @all } = @names;
606 68 for my $entry (@tables) {
607 129 my %seen;
608 my @unique;
609 129 for my $fk (@{ $entry->{fks} }) {
610 57 my $name = $by_ref{"$fk"};
611 57 ▶ next if $seen{$name}++; # one name is one foreign key: an identical one is written once
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$name}++ 3 54 57
612 push @unique, [ $fk->{to_table}, sprintf 'CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s(%s)%s',
613 quote_ident($name),
614 57 join(', ', map { quote_ident($_) } @{ $fk->{from_columns} }),
615 quote_ident($fk->{to_table}),
616 57 join(', ', map { quote_ident($_) } @{ $fk->{to_columns} }),
617 54 $fk->{on_update} . $fk->{on_delete} ];
618 }
619 129 $entry->{fks} = \@unique;
620 }
621 }
622  
623 # The tables go out parents first (order_by_foreign_keys); the foreign keys
624 # held back are added with ALTER TABLE once all tables and indexes exist.
625 68 my (@stmts, @late);
626 68 ▶ for my $step (order_by_foreign_keys(\@tables, sub { $_[0][0] })) {
Subroutine __ANON__: called CC=1 SCAR=0.0
627 129 my ($pick, $inline, $held) = @$step{qw(table inline held)};
628 push @stmts, sprintf "CREATE TABLE %s (\n%s\n%s",
629 quote_table($pick->{name}),
630 129 join(",\n", @{ $pick->{col_defs} }, map { " $_->[1]" } @$inline),
631 129 $pick->{tail};
632 129 push @stmts, @{ $pick->{index_stmts} };
633 129 push @late, map { sprintf 'ALTER TABLE %s ADD %s;', quote_table($pick->{name}), $_->[1] } @$held;
634 }
635  
636 68 my @view_stmts = map { sprintf "CREATE VIEW %s AS %s;", quote_ident($_), $view_def{$_} } order_views(\%view_def);
637  
638 67 return join "
639  
640 ", @stmts, @late, @view_stmts;
641 }
642  
643 316 ▶sub _mysql_column_type {
Subroutine _mysql_column_type: called CC=27 SCAR=33.4
644 316 my ($info) = @_;
645 316 ▶ my $type = $info->{data_type} // 'text';
Condition50%1/2
$info->{"data_type"} // "text"
l!l
3160
MC/DC0%0/1
$info->{"data_type"} // "text"
$info->{"data_type"}
Truth table50%1/2
A
A= $info->{"data_type"}
Aresult
11
00
646  
647 # Pre-parameterized types pass through
648 316 ▶ return $type if $type =~ /\(.+\)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /\(.+\)$/ 0 316 316
649  
650 # Portable base types: delegate to the adapter (single source of truth).
651 # canonical_column refuses a broken declaration (a size that is neither a
652 # scalar nor an arrayref); that is the declaration's error and goes to the
653 # caller, not into the alias path below (karr k96).
654 316 ▶ if (DBIO::Schema::Type::is_base_type(lc $type)) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIO::Schema::Type::is_base_type(lc $type)) 220 96 316
655 220 return $ADAPTER->to_native(DBIO::Schema::Type::canonical_column('_', $info));
656 }
657  
658 # GUID. Neither MySQL nor MariaDB has such a type; the column holds the
659 # string form, 36 characters hyphenated, as the rest of the family spells it
660 # (dbio-sybase k52). The width is the type's own: a declared size does not
661 # move it. What is introspected back is varchar(36), so a diff finds nothing
662 # to change (karr k115).
663 96 ▶ return 'varchar(36)' if lc $type eq 'uniqueidentifier';
Branch: 1 branch
BranchTrueFalseTotal
if lc $type eq "uniqueidentifier" 3 93 96
664  
665 # ENUM and SET carry their members in extra => { list => [...] } (the
666 # DBIx::Class spelling). Each member is a string literal of its own, written
667 # like a default (apostrophe doubled, backslash doubled), so a member that
668 # holds a quote is the member and not the end of the list (karr k120).
669 93 ▶ if (lc($type) =~ /\A(?:enum|set)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($type) =~ /\A(?:enum|set)\z/) 2 91 93
670 2 ▶ my $list = ref $info->{extra} eq 'HASH' ? $info->{extra}{list} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $info->{'extra'} eq 'HASH' ? : 2 0 2
671 2 ▶ return "$type(" . join(',', map { DBIO::MySQL::DefaultValue::default_sql($_, 0) } @$list) . ')'
Branch: 1 branch
BranchTrueFalseTotal
if ref $list eq "ARRAY" and @$list 2 0 2
Condition33%1/3
ref $list eq "ARRAY" and @$list
!ll&&!rl&&r
002
MC/DC0%0/2
ref $list eq "ARRAY" and @$list
ref $list eq "ARRAY" @$list
Truth table33%1/3
A and B
A= ref $list eq "ARRAY"B= @$list
ABresult
0X0
100
111
672 if ref $list eq 'ARRAY' && @$list;
673 }
674  
675 # Use size for varchar/varbinary/binary (non-base alias path).
676 # All three take exactly ONE scalar length (VARCHAR(M), BINARY[(M)],
677 # VARBINARY(M)), so an arrayref size would stringify the reference into the
678 # type -- varchar(ARRAY(0x...)). Read its first element instead: the same
679 # "first member is the width" reading `character` gets below, and a size
680 # naming no width falls through to the legacy default (karr #37).
681 91 ▶ if ($info->{size} && $type =~ /^(varchar|varbinary|binary)$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"size"} and $type =~ /^(varchar|varbinary|binary)$/i) 31 60 91
Condition100%3/3
$info->{"size"} and $type =~ /^(varchar|varbinary|binary)$/i
!ll&&!rl&&r
461431
MC/DC100%2/2
$info->{"size"} and $type =~ /^(varchar|varbinary|binary)$/i
$info->{"size"} $type =~ /^(varchar|varbinary|binary)$/i
Truth table100%3/3
A and B
A= $info->{"size"}B= $type =~ /^(varchar|varbinary|binary)$/i
ABresult
0X0
100
111
682 31 ▶ my $size = ref $info->{size} eq 'ARRAY' ? $info->{size}[0] : $info->{size};
Branch: 1 branch
BranchTrueFalseTotal
ref $info->{'size'} eq 'ARRAY' ? : 7 24 31
683 31 ▶ return "$type($size)" if $size;
Branch: 1 branch
BranchTrueFalseTotal
if $size 30 1 31
684 }
685  
686 # Legacy / dialect alias names — only aliases, not the 8 base-type names
687 61 my %type_map = (
688 int => 'int',
689 bigint => 'bigint',
690 smallint => 'smallint',
691 tinyint => 'tinyint',
692 serial => 'int',
693 bigserial => 'bigint',
694  
695 varchar => 'varchar(255)',
696 string => 'text',
697 clob => 'longtext',
698  
699 float => 'float',
700 real => 'double',
701 'double precision' => 'double',
702 decimal => 'decimal(10,2)',
703  
704 bytea => 'blob',
705  
706 # no such type here; DECIMAL(19,4) is what MONEY is on SQL Server (karr k115)
707 money => 'decimal(19,4)',
708  
709 date => 'date',
710 datetime => 'datetime',
711 time => 'time',
712 json => 'json',
713 );
714  
715 61 ▶ my $native = $type_map{ lc $type } // $type;
Condition66%2/3
$type_map{lc $type} // $type
l!l&&r!l&&!r
5470
MC/DC0%0/2
$type_map{lc $type} // $type
$type_map{lc $type} $type
Truth table66%2/3
A // B
A= $type_map{lc $type}B= $type
ABresult
1X1
011
000
716  
717 # decimal/character are %ALIAS-only names (DBIO::Schema::Type) -- they never
718 # reach the portable base-type path above, so the plain lookup above would
719 # otherwise hardcode a size (decimal(10,2)) or drop it entirely (character).
720 # Honor an explicit size the same way the portable path already does for
721 # numeric/char, falling back to the legacy default only when size is absent.
722 # decimal accepts every size shape a caller can write: [precision, scale],
723 # a precision-only [precision], and a bare scalar precision. The last two
724 # render decimal($p) -- MySQL's DECIMAL(M) is DECIMAL(M,0), and it is the
725 # spelling DBIO::MSSQL::DDL::_mssql_column_type already uses for a
726 # precision-only size, so this is not a third convention (karr #26).
727 61 ▶ if (lc($type) eq 'decimal' && defined $info->{size}) {
Branch: 3 branches
BranchTrueFalseTotal
if (lc $type eq 'decimal' and defined $info->{'size'}) { } 9 52 61
elsif (lc $type eq 'bit' and defined $info->{'size'}) { } 1 51 52
elsif (lc $type eq 'character' and defined $info->{'size'}) { } 4 93 97
Condition100%3/3
lc $type eq "decimal" and defined $info->{"size"}
!ll&&!rl&&r
5119
MC/DC100%2/2
lc $type eq "decimal" and defined $info->{"size"}
lc $type eq "decimal" defined $info->{"size"}
Truth table100%3/3
A and B
A= lc $type eq "decimal"B= defined $info->{"size"}
ABresult
0X0
100
111
728 my ($precision, $scale) = ref $info->{size} eq 'ARRAY'
729 6 ? @{ $info->{size} }
730 9 ▶ : ($info->{size}, undef);
Branch: 1 branch
BranchTrueFalseTotal
ref $info->{'size'} eq 'ARRAY' ? : 6 3 9
731 9 ▶ if (defined $precision) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $precision) 8 1 9
732 8 ▶ $native = defined $scale ? "decimal($precision,$scale)" : "decimal($precision)";
Branch: 1 branch
BranchTrueFalseTotal
defined $scale ? : 3 5 8
733 }
734 }
735 ▶ elsif (lc($type) eq 'bit' && defined $info->{size}) {
Condition100%3/3
lc $type eq "bit" and defined $info->{"size"}
!ll&&!rl&&r
5011
MC/DC100%2/2
lc $type eq "bit" and defined $info->{"size"}
lc $type eq "bit" defined $info->{"size"}
Truth table100%3/3
A and B
A= lc $type eq "bit"B= defined $info->{"size"}
ABresult
0X0
100
111
736 # BIT(M) is the number of bits; without the size the server makes BIT(1)
737 # (karr k120).
738 1 ▶ my $size = ref $info->{size} eq 'ARRAY' ? $info->{size}[0] : $info->{size};
Branch: 1 branch
BranchTrueFalseTotal
ref $info->{'size'} eq 'ARRAY' ? : 0 1 1
739 1 ▶ $native = "bit($size)" if defined $size;
Branch: 1 branch
BranchTrueFalseTotal
if defined $size 1 0 1
740 }
741 ▶ elsif (lc($type) eq 'character' && defined $info->{size}) {
Condition100%3/3
lc $type eq "character" and defined $info->{"size"}
!ll&&!rl&&r
4614
MC/DC100%2/2
lc $type eq "character" and defined $info->{"size"}
lc $type eq "character" defined $info->{"size"}
Truth table100%3/3
A and B
A= lc $type eq "character"B= defined $info->{"size"}
ABresult
0X0
100
111
742 # The mirror-image of the above: character takes a scalar length, so an
743 # arrayref size would stringify the reference into the type name. Read
744 # its first element -- the same "first member is the width" reading
745 # decimal gives a precision-only arrayref.
746 4 ▶ my $size = ref $info->{size} eq 'ARRAY' ? $info->{size}[0] : $info->{size};
Branch: 1 branch
BranchTrueFalseTotal
ref $info->{'size'} eq 'ARRAY' ? : 2 2 4
747 4 ▶ $native = "character($size)" if defined $size;
Branch: 1 branch
BranchTrueFalseTotal
if defined $size 4 0 4
748 }
749  
750 61 return $native;
751 }
752  
753 86 1;
754  
755 __END__
« xbin/dbio-mysql-k8s ↑ Summary blib/lib/DBIO/MySQL/Introspect/Indexes.pm »