| 1 | package DBIO::MSSQL::Adapter; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: MSSQL base->native type resolver | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 66 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 66 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 66 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 66 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 66 | ▶ | use base 'DBIO::Adapter::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # Native MSSQL type for each portable base type. Mirrors the sibling | ||||||||||||||||||||||||||||
| 13 | # drivers (DBIO::MySQL::Adapter, DBIO::PostgreSQL::Adapter): the eight | ||||||||||||||||||||||||||||
| 14 | # base types are the single source of truth, resolved here. | ||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||
| 16 | # - integer promotes to bigint, as in MySQL/PostgreSQL. | ||||||||||||||||||||||||||||
| 17 | # - text/blob use the unbounded (max) variants; the legacy `text`/`image` | ||||||||||||||||||||||||||||
| 18 | # types are deprecated in modern MSSQL. | ||||||||||||||||||||||||||||
| 19 | # - timestamp maps to `datetime` (not datetime2) to stay aligned with | ||||||||||||||||||||||||||||
| 20 | # DBIO::MSSQL::Storage::DateTime::Format, whose %3N pattern is the | ||||||||||||||||||||||||||||
| 21 | # datetime millisecond format. | ||||||||||||||||||||||||||||
| 22 | 66 | my %NATIVE = ( | |||||||||||||||||||||||||||
| 23 | integer => 'bigint', | ||||||||||||||||||||||||||||
| 24 | text => 'nvarchar(max)', | ||||||||||||||||||||||||||||
| 25 | boolean => 'bit', | ||||||||||||||||||||||||||||
| 26 | double => 'float', | ||||||||||||||||||||||||||||
| 27 | blob => 'varbinary(max)', | ||||||||||||||||||||||||||||
| 28 | timestamp => 'datetime', | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 663 | ▶ | sub to_native { | ||||||||||||||||||||||||||
|
Subroutine
to_native: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 663 | my ($self, $col) = @_; | |||||||||||||||||||||||||||
| 33 | 663 | my $b = $col->{base_type}; | |||||||||||||||||||||||||||
| 34 | 663 | ▶ | return 'nchar(' . ($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"}
| |||||||||||||||||||||||||||||
| 35 | 643 | ▶ | if ($b eq 'numeric') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 8 | my ($p, $s) = @{$col}{qw/precision scale/}; | |||||||||||||||||||||||||||
| 37 | 8 | ▶ | return (defined $p && defined $s) ? "numeric($p,$s)" : 'numeric'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $p and defined $s
MC/DC50%1/2
defined $p and defined $s
defined $p
defined $s
Truth table66%2/3
A and B
A= defined $pB= defined $s
| |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 635 | ▶ | return $NATIVE{$b} // croak "no MSSQL native type for base '$b'"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$NATIVE{$b} // croak("no MSSQL native type for base '${b}'")
MC/DC0%0/1
$NATIVE{$b} // croak("no MSSQL native type for base '${b}'")
$NATIVE{$b}
Truth table50%1/2
A
A= $NATIVE{$b}
| |||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # capabilities inherited from DBIO::Adapter::Base: supports_alter_column_type => 1 | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 66 | 1; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | __END__ | ||||||||||||||||||||||||||||