| 1 | package DBIO::MSSQL::Adapter; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: MSSQL base->native type resolver | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use base 'DBIO::Adapter::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # Native MSSQL type for each portable base type. Mirrors the sibling | ||||||||||||||||||||||||||||
| 10 | # drivers (DBIO::MySQL::Adapter, DBIO::PostgreSQL::Adapter): the eight | ||||||||||||||||||||||||||||
| 11 | # base types are the single source of truth, resolved here. | ||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||
| 13 | # - integer promotes to bigint, as in MySQL/PostgreSQL. | ||||||||||||||||||||||||||||
| 14 | # - text/blob use the unbounded (max) variants; the legacy `text`/`image` | ||||||||||||||||||||||||||||
| 15 | # types are deprecated in modern MSSQL. | ||||||||||||||||||||||||||||
| 16 | # - timestamp maps to `datetime` (not datetime2) to stay aligned with | ||||||||||||||||||||||||||||
| 17 | # DBIO::MSSQL::Storage::DateTime::Format, whose %3N pattern is the | ||||||||||||||||||||||||||||
| 18 | # datetime millisecond format. | ||||||||||||||||||||||||||||
| 19 | 3 | my %NATIVE = ( | |||||||||||||||||||||||||||
| 20 | integer => 'bigint', | ||||||||||||||||||||||||||||
| 21 | text => 'nvarchar(max)', | ||||||||||||||||||||||||||||
| 22 | boolean => 'bit', | ||||||||||||||||||||||||||||
| 23 | double => 'float', | ||||||||||||||||||||||||||||
| 24 | blob => 'varbinary(max)', | ||||||||||||||||||||||||||||
| 25 | timestamp => 'datetime', | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub to_native { | ||||||||||||||||||||||||||
|
Subroutine
to_native: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 0 | my ($self, $col) = @_; | |||||||||||||||||||||||||||
| 30 | 0 | my $b = $col->{base_type}; | |||||||||||||||||||||||||||
| 31 | 0 | ▶ | return 'nchar(' . ($col->{size} // 255) . ')' if $b eq 'char'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$col->{"size"} // 255
MC/DC0%0/1
$col->{"size"} // 255
$col->{"size"}
Truth table0%0/2
A
A= $col->{"size"}
| |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if ($b eq 'numeric') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | my ($p, $s) = @{$col}{qw/precision scale/}; | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | return (defined $p && defined $s) ? "numeric($p,$s)" : 'numeric'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $p and defined $s
MC/DC0%0/2
defined $p and defined $s
defined $p
defined $s
Truth table0%0/3
A and B
A= defined $pB= defined $s
| |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | return $NATIVE{$b} // croak "no MSSQL native type for base '$b'"; | ||||||||||||||||||||||||||
|
Condition0%0/3
$NATIVE{$b} // croak("no MSSQL native type for base '${b}'")
MC/DC0%0/2
$NATIVE{$b} // croak("no MSSQL native type for base '${b}'")
$NATIVE{$b}
croak("no MSSQL native type for base '${b}'")
Truth table0%0/3
A // B
A= $NATIVE{$b}B= croak("no MSSQL native type for base '${b}'")
| |||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # capabilities inherited from DBIO::Adapter::Base: supports_alter_column_type => 1 | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 3 | 1; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | __END__ | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =pod | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =head1 NAME | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | DBIO::MSSQL::Adapter - MSSQL base->native type resolver | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =head1 VERSION | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | version 0.900001 | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | DBIO & DBIx::Class Authors | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Copyright (C) 2026 DBIO Authors | ||||||||||||||||||||||||||||
| 64 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||||||||||||||||||||||||||||
| 65 | Based on DBIx::Class, heavily modified. | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 68 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =cut | ||||||||||||||||||||||||||||