blib/lib/DBIO/MySQL/Adapter.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 10 / 10 Conditioncond 100% 7 / 7 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 6 / 6 Podpod 50.0% 1 / 2 totaltotal 96.6% 58 / 60 CC 9 SCAR 16.4
CC
9
Cov
100%
to_native
8.0
no_charset_for
2.0
BEGIN
1.0
CRAP 5.1
« blib/lib/DBIO/MySQL/IndexType.pm ↑ Summary blib/lib/DBIO/MySQL/Identifier.pm »
1 package DBIO::MySQL::Adapter;
2 # ABSTRACT: MySQL base->native type resolver
3  
4 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 87 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 87 our $VERSION = '0.900007';
8  
9 87 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 87 ▶use base 'DBIO::Adapter::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 87 my %NATIVE = (
13 integer => 'BIGINT',
14 text => 'LONGTEXT',
15 boolean => 'TINYINT(1)',
16 double => 'DOUBLE',
17 blob => 'LONGBLOB',
18 timestamp => 'DATETIME',
19 );
20  
21 # Native types whose information_schema row reports character_set_name and
22 # collation_name as NULL (binary, numeric, datetime families). Text families
23 # (CHAR, VARCHAR, LONGTEXT, …) get a server-assigned charset and we do not
24 # preserve that on round-trip -- see DBIO::MySQL::Diff ESCALATION NOTE.
25 87 my %NO_CHARSET = map { $_ => 1 } qw(
26 bigint tinyint double decimal longblob datetime
27 );
28  
29 235 ▶sub to_native {
Subroutine to_native: called CC=8 SCAR=20.8
Pod documented
30 235 my ($self, $col) = @_;
31 235 my $b = $col->{base_type};
32 235 ▶ return 'CHAR(' . ($col->{size} // 255) . ')' if $b eq 'char';
Branch: 1 branch
BranchTrueFalseTotal
if $b eq "char" 5 230 235
Condition100%2/2
$col->{"size"} // 255
l!l
41
MC/DC100%1/1
$col->{"size"} // 255
$col->{"size"}
Truth table100%2/2
A
A= $col->{"size"}
Aresult
11
00
33 230 ▶ if ($b eq 'numeric') {
Branch: 1 branch
BranchTrueFalseTotal
if ($b eq "numeric") 9 221 230
34 9 my ($p, $s) = @{$col}{qw/precision scale/};
35 9 ▶ return "DECIMAL($p,$s)" if defined $p && defined $s;
Branch: 1 branch
BranchTrueFalseTotal
if defined $p and defined $s 3 6 9
Condition100%3/3
defined $p and defined $s
!ll&&!rl&&r
333
MC/DC100%2/2
defined $p and defined $s
defined $p defined $s
Truth table100%3/3
A and B
A= defined $pB= defined $s
ABresult
0X0
100
111
36 # precision without scale: DECIMAL(p) -- MySQL's DECIMAL(M) is DECIMAL(M,0),
37 # the same spelling the decimal alias path renders (karr #41, #26).
38 6 ▶ return "DECIMAL($p)" if defined $p;
Branch: 1 branch
BranchTrueFalseTotal
if defined $p 3 3 6
39 3 return 'DECIMAL';
40 }
41 221 ▶ return $NATIVE{$b} // croak "no MySQL native type for base '$b'";
Condition100%2/2
$NATIVE{$b} // croak("no MySQL native type for base '${b}'")
l!l
2201
MC/DC0%0/1
$NATIVE{$b} // croak("no MySQL native type for base '${b}'")
$NATIVE{$b}
Truth table50%1/2
A
A= $NATIVE{$b}
Aresult
11
00
42 }
43  
44 # True when the given native type (e.g. "BIGINT", "DECIMAL(10,2)", "DATETIME")
45 # is from a family whose information_schema row never carries a character
46 # set / collation. Used by Diff::target_from_compiled to leave those fields
47 # undef on the target side of the comparison.
48 8 ▶sub no_charset_for {
Subroutine no_charset_for: called CC=2 SCAR=6.9
Pod undocumented
49 8 my ($self, $native) = @_;
50 8 my $lc = lc $native;
51 8 $lc =~ s/\(.*//; # strip "(10,2)" parameters
52 8 ▶ return exists $NO_CHARSET{$lc} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $NO_CHARSET{$lc} ? : 7 1 8
53 }
54  
55 # capabilities inherited from DBIO::Adapter::Base: supports_alter_column_type => 1
56  
57 87 1;
58  
59 __END__
« blib/lib/DBIO/MySQL/IndexType.pm ↑ Summary blib/lib/DBIO/MySQL/Identifier.pm »