| 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
Condition100%2/2
$col->{"size"} // 255
MC/DC100%1/1
$col->{"size"} // 255
$col->{"size"}
Truth table100%2/2
A
A= $col->{"size"}
| |||||||||||||||||||||||||||||
| 33 | 230 | ▶ | if ($b eq 'numeric') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 9 | my ($p, $s) = @{$col}{qw/precision scale/}; | |||||||||||||||||||||||||||
| 35 | 9 | ▶ | return "DECIMAL($p,$s)" if defined $p && defined $s; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $p and defined $s
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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}'")
MC/DC0%0/1
$NATIVE{$b} // croak("no MySQL native type for base '${b}'")
$NATIVE{$b}
Truth table50%1/2
A
A= $NATIVE{$b}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # capabilities inherited from DBIO::Adapter::Base: supports_alter_column_type => 1 | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 87 | 1; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | __END__ | ||||||||||||||||||||||||||||