DB2/Type.pm

filter: Statementstmt 100% 21 / 21 Branchbran 83.3% 5 / 6 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 79.5% 35 / 44 CC 7 SCAR 17.1
CC
7
Cov
86%
_db2_column_type
7.4
BEGIN
1.0
BEGIN
1.0
CRAP 5.5
« DB2/Diff/Table.pm ↑ Summary DB2/SQLMaker.pm »
1 package DBIO::DB2::Type;
2 # ABSTRACT: DB2 column type utilities
3  
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 our @EXPORT_OK = qw(_db2_column_type);
10  
11 33 ▶sub _db2_column_type {
Subroutine _db2_column_type: called CC=7 SCAR=20.1
12 33 my ($info, $size) = @_;
13  
14 # Support both hashref form (DDL.pm) and ($type, $size) form (Diff modules)
15 33 ▶ if (ref $info eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $info eq "HASH") 7 26 33
16 7 $size = $info->{size};
17 7 $info = $info->{data_type};
18 }
19  
20 33 ▶ my $type = $info // 'VARCHAR';
Condition50%1/2
$info // "VARCHAR"
l!l
330
MC/DC0%0/1
$info // "VARCHAR"
$info
Truth table50%1/2
A
A= $info
Aresult
11
00
21  
22 33 ▶ return $type if $type =~ /\(.+\)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /\(.+\)$/ 0 33 33
23  
24 33 my %type_map = (
25 tinyint => 'SMALLINT',
26 smallint => 'SMALLINT',
27 int => 'INTEGER',
28 integer => 'INTEGER',
29 bigint => 'BIGINT',
30 serial => 'INTEGER',
31 bigserial => 'BIGINT',
32 real => 'REAL',
33 float => 'FLOAT',
34 double => 'DOUBLE PRECISION',
35 'double precision' => 'DOUBLE PRECISION',
36 numeric => 'DECIMAL',
37 decimal => 'DECIMAL',
38 text => 'VARCHAR',
39 varchar => 'VARCHAR',
40 char => 'CHAR',
41 clob => 'CLOB',
42 boolean => 'SMALLINT',
43 bool => 'SMALLINT',
44 blob => 'BLOB',
45 binary => 'BLOB',
46 varbinary => 'VARBINARY',
47 date => 'DATE',
48 time => 'TIME',
49 datetime => 'TIMESTAMP',
50 timestamp => 'TIMESTAMP',
51 timestamptz => 'TIMESTAMP',
52 'timestamp with time zone' => 'TIMESTAMP',
53 interval => 'INTERVAL',
54 uuid => 'CHAR(16)',
55 json => 'VARCHAR',
56 );
57  
58 33 ▶ my $mapped = $type_map{ lc $type } // uc $type;
Condition33%1/3
$type_map{lc $type} // uc $type
l!l&&r!l&&!r
3300
MC/DC0%0/2
$type_map{lc $type} // uc $type
$type_map{lc $type} uc $type
Truth table33%1/3
A // B
A= $type_map{lc $type}B= uc $type
ABresult
1X1
011
000
59 33 ▶ return $mapped unless defined $size && length $size;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size and length $size 28 5 33
Condition66%2/3
defined $size and length $size
!ll&&!rl&&r
2805
MC/DC50%1/2
defined $size and length $size
defined $size length $size
Truth table66%2/3
A and B
A= defined $sizeB= length $size
ABresult
0X0
100
111
60 5 return "$mapped($size)";
61 }
62  
63 5 1;
64  
65 __END__
66  
67 =pod
68  
69 =encoding UTF-8
70  
71 =head1 NAME
72  
73 DBIO::DB2::Type - DB2 column type utilities
74  
75 =head1 VERSION
76  
77 version 0.900001
78  
79 =head1 AUTHOR
80  
81 DBIO & DBIx::Class Authors
82  
83 =head1 COPYRIGHT AND LICENSE
84  
85 Copyright (C) 2026 DBIO Authors
86 Portions Copyright (C) 2005-2025 DBIx::Class Authors
87 Based on DBIx::Class, heavily modified.
88  
89 This is free software; you can redistribute it and/or modify it under
90 the same terms as the Perl 5 programming language system itself.
91  
92 =cut
« DB2/Diff/Table.pm ↑ Summary DB2/SQLMaker.pm »