Firebird/Type.pm

filter: Statementstmt 100% 64 / 64 Branchbran 97.1% 68 / 70 Conditioncond 91.5% 76 / 83 MC/DCmcdc 83.3% 35 / 42 Subroutinesub 100% 10 / 10 Podpod 100% 7 / 7 totaltotal 94.2% 260 / 276 CC 67 SCAR 33.0
CC
67
Cov
96%
ddl_type_from_info
42.4
sql_type_from_rdb
15.0
lob_kind
4.0
CRAP 27.1
« Firebird/Diff/Constraint.pm ↑ Summary Firebird/Storage/InterBase.pm »
1 package DBIO::Firebird::Type;
2 # ABSTRACT: Firebird type-system mapping (introspection + DDL directions)
3  
4 43 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 43 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 43 our $VERSION = '0.900007';
8  
9 43 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 43 our @EXPORT_OK = qw(sql_type_from_rdb ddl_type_from_info render_size is_boolean_type is_binary_type is_numeric_type lob_kind);
12  
13  
14 # rdb$field_type number -> bare SQL type name (no size/precision; size is
15 # carried separately in the introspected model). Numbers as the server stores
16 # them in rdb$fields; the sub_type/charset-dependent ones (7/8/16/26 numeric
17 # and decimal, 14/37 binary, 261 blob) are resolved in sql_type_from_rdb.
18 43 my %RDB_TYPE = (
19 7 => 'smallint',
20 8 => 'integer',
21 9 => 'quad',
22 10 => 'float',
23 12 => 'date',
24 13 => 'time',
25 14 => 'char',
26 16 => 'bigint',
27 23 => 'boolean',
28 24 => 'decfloat',
29 26 => 'int128',
30 27 => 'double precision',
31 28 => 'time with time zone',
32 29 => 'timestamp with time zone',
33 35 => 'timestamp',
34 37 => 'varchar',
35 40 => 'cstring',
36 261 => 'blob',
37 );
38  
39 # Exact-number storage types; rdb$field_sub_type 1 = NUMERIC, 2 = DECIMAL,
40 # 0 = the plain integer type.
41 43 my %NUMERIC_STORAGE = map { $_ => 1 } (7, 8, 16, 26);
42  
43 # rdb$character_set_id of OCTETS: CHAR/VARCHAR columns in it are BINARY/VARBINARY.
44 43 my $CHARSET_OCTETS = 1;
45  
46  
47 30 ▶sub sql_type_from_rdb {
Subroutine sql_type_from_rdb: called CC=15 SCAR=27.1
Pod documented
48 30 my ($type_num, $sub_type, $charset_id) = @_;
49 30 ▶ $type_num //= -1;
Condition50%1/2
$type_num //= -1
l!l
300
MC/DC0%0/1
$type_num //= -1
$type_num
Truth table50%1/2
A
A= $type_num
Aresult
11
00
50 30 ▶ $sub_type //= 0;
Condition100%2/2
$sub_type //= 0
l!l
1515
MC/DC100%1/1
$sub_type //= 0
$sub_type
Truth table100%2/2
A
A= $sub_type
Aresult
11
00
51  
52 30 ▶ if ($NUMERIC_STORAGE{$type_num} && ($sub_type == 1 || $sub_type == 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($NUMERIC_STORAGE{$type_num} and $sub_type == 1 || $sub_type == 2) 4 26 30
Condition100%6/6
$NUMERIC_STORAGE{$type_num} and $sub_type == 1 || $sub_type == 2
!ll&&!rl&&r
1884
$sub_type == 1 or $sub_type == 2
l!l&&r!l&&!r
318
MC/DC100%3/3
$NUMERIC_STORAGE{$type_num} and $sub_type == 1 || $sub_type == 2
$NUMERIC_STORAGE{$type_num} $sub_type == 1 $sub_type == 2
Truth table100%4/4
A and B or C
A= $NUMERIC_STORAGE{$type_num}B= $sub_type == 1C= $sub_type == 2
ABCresult
0XX0
1000
11X1
1011
53 4 ▶ return $sub_type == 1 ? 'numeric' : 'decimal';
Branch: 1 branch
BranchTrueFalseTotal
$sub_type == 1 ? : 3 1 4
54 }
55 26 ▶ if ($type_num == 261) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_num == 261) 2 24 26
56 2 ▶ return $sub_type == 1 ? 'blob sub_type text' : 'blob';
Branch: 1 branch
BranchTrueFalseTotal
$sub_type == 1 ? : 1 1 2
57 }
58 24 ▶ if (($type_num == 14 || $type_num == 37) && ($charset_id // -1) == $CHARSET_OCTETS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_num == 14 || $type_num == 37 and ($charset_id // -1) == $CHARSET_OCTETS) 2 22 24
Condition100%8/8
$type_num == 14 || $type_num == 37 and ($charset_id // -1) == $CHARSET_OCTETS
!ll&&!rl&&r
1932
$type_num == 14 or $type_num == 37
l!l&&r!l&&!r
2319
$charset_id // -1
l!l
32
MC/DC100%3/3
$type_num == 14 || $type_num == 37 and ($charset_id // -1) == $CHARSET_OCTETS
$type_num == 14 $type_num == 37 $charset_id
Truth table100%5/5
A or B and C
A= $type_num == 14B= $type_num == 37C= $charset_id
ABCresult
00X0
1X00
0100
1X11
0111
59 2 ▶ return $type_num == 14 ? 'binary' : 'varbinary';
Branch: 1 branch
BranchTrueFalseTotal
$type_num == 14 ? : 1 1 2
60 }
61 22 ▶ return $RDB_TYPE{$type_num} // 'varchar';
Condition100%2/2
$RDB_TYPE{$type_num} // "varchar"
l!l
211
MC/DC100%1/1
$RDB_TYPE{$type_num} // "varchar"
$RDB_TYPE{$type_num}
Truth table100%2/2
A
A= $RDB_TYPE{$type_num}
Aresult
11
00
62 }
63  
64  
65 796 ▶sub ddl_type_from_info {
Subroutine ddl_type_from_info: called CC=42 SCAR=37.5
Pod documented
66 796 my ($info) = @_;
67 796 ▶ my $type = lc($info->{data_type} // 'varchar');
Condition100%2/2
$info->{"data_type"} // "varchar"
l!l
7906
MC/DC100%1/1
$info->{"data_type"} // "varchar"
$info->{"data_type"}
Truth table100%2/2
A
A= $info->{"data_type"}
Aresult
11
00
68 796 my $size = $info->{size};
69 796 ▶ return 'INTEGER' if $type eq 'integer' || $type eq 'int';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "integer" or $type eq "int" 392 404 796
Condition100%3/3
$type eq "integer" or $type eq "int"
l!l&&r!l&&!r
36824404
MC/DC100%2/2
$type eq "integer" or $type eq "int"
$type eq "integer" $type eq "int"
Truth table100%3/3
A or B
A= $type eq "integer"B= $type eq "int"
ABresult
1X1
011
000
70 404 ▶ return 'BIGINT' if $type eq 'bigint';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "bigint" 22 382 404
71 382 ▶ return 'SMALLINT' if $type eq 'smallint' || $type eq 'tinyint';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "smallint" or $type eq "tinyint" 43 339 382
Condition100%3/3
$type eq "smallint" or $type eq "tinyint"
l!l&&r!l&&!r
2221339
MC/DC100%2/2
$type eq "smallint" or $type eq "tinyint"
$type eq "smallint" $type eq "tinyint"
Truth table100%3/3
A or B
A= $type eq "smallint"B= $type eq "tinyint"
ABresult
1X1
011
000
72 339 ▶ return 'BIGINT' if $type eq 'bigserial' || $type eq 'serial';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "bigserial" or $type eq "serial" 1 338 339
Condition66%2/3
$type eq "bigserial" or $type eq "serial"
l!l&&r!l&&!r
01338
MC/DC50%1/2
$type eq "bigserial" or $type eq "serial"
$type eq "bigserial" $type eq "serial"
Truth table66%2/3
A or B
A= $type eq "bigserial"B= $type eq "serial"
ABresult
1X1
011
000
73 # the core canon: string without a size is text, with one it is VARCHAR(n)
74 338 ▶ return defined $size ? 'VARCHAR' . render_size($size) : 'BLOB SUB_TYPE TEXT' if $type eq 'string';
Branch: 2 branches
BranchTrueFalseTotal
if $type eq "string" 4 334 338
defined $size ? : 1 3 4
75 334 ▶ return 'VARCHAR' . (render_size($size) || '(255)')
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "varchar" or $type eq "nvarchar" or $type eq "character varying" 91 243 334
Condition100%8/8
$type eq "varchar" or $type eq "nvarchar" or $type eq "character varying"
l!l&&r!l&&!r
901243
$type eq "varchar" or $type eq "nvarchar"
l!l&&r!l&&!r
891244
render_size($size) || '(255)'
l!l
5833
MC/DC100%3/3
$type eq "varchar" or $type eq "nvarchar" or $type eq "character varying"
$type eq "varchar" $type eq "nvarchar" $type eq "character varying"
MC/DC100%1/1
render_size($size) || '(255)'
render_size($size)
Truth table100%4/4
A or B or C
A= $type eq "varchar"B= $type eq "nvarchar"C= $type eq "character varying"
ABCresult
1XX1
01X1
0011
0000
Truth table100%2/2
A
A= render_size($size)
Aresult
11
00
76 if $type eq 'varchar' || $type eq 'nvarchar' || $type eq 'character varying';
77 243 ▶ return 'CHAR' . (render_size($size) || '(1)') if $type eq 'char' || $type eq 'nchar' || $type eq 'character';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "char" or $type eq "nchar" or $type eq "character" 14 229 243
Condition100%8/8
$type eq "char" or $type eq "nchar" or $type eq "character"
l!l&&r!l&&!r
131229
$type eq "char" or $type eq "nchar"
l!l&&r!l&&!r
121230
render_size($size) || '(1)'
l!l
131
MC/DC100%3/3
$type eq "char" or $type eq "nchar" or $type eq "character"
$type eq "char" $type eq "nchar" $type eq "character"
MC/DC100%1/1
render_size($size) || '(1)'
render_size($size)
Truth table100%4/4
A or B or C
A= $type eq "char"B= $type eq "nchar"C= $type eq "character"
ABCresult
1XX1
01X1
0011
0000
Truth table100%2/2
A
A= render_size($size)
Aresult
11
00
78 229 ▶ return 'BINARY' . (render_size($size) || '(1)') if $type eq 'binary';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "binary" 4 225 229
Condition50%1/2
render_size($size) || '(1)'
l!l
40
MC/DC0%0/1
render_size($size) || '(1)'
render_size($size)
Truth table50%1/2
A
A= render_size($size)
Aresult
11
00
79 225 ▶ return 'VARBINARY' . (render_size($size) || '(255)') if $type eq 'varbinary';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "varbinary" 4 221 225
Condition50%1/2
render_size($size) || '(255)'
l!l
40
MC/DC0%0/1
render_size($size) || '(255)'
render_size($size)
Truth table50%1/2
A
A= render_size($size)
Aresult
11
00
80 221 ▶ return 'BLOB' if $type eq 'bytea' || $type eq 'blob';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "bytea" or $type eq "blob" 20 201 221
Condition66%2/3
$type eq "bytea" or $type eq "blob"
l!l&&r!l&&!r
020201
MC/DC50%1/2
$type eq "bytea" or $type eq "blob"
$type eq "bytea" $type eq "blob"
Truth table66%2/3
A or B
A= $type eq "bytea"B= $type eq "blob"
ABresult
1X1
011
000
81 201 ▶ return 'BLOB SUB_TYPE TEXT'
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "text" or $type eq "clob" or $type eq "long" or $type eq "mediumtext" or $type eq "longtext" 51 150 201
Condition83%10/12
$type eq "text" or $type eq "clob" or $type eq "long" or $type eq "mediumtext" or $type eq "longtext"
l!l&&r!l&&!r
501150
$type eq "text" or $type eq "clob" or $type eq "long" or $type eq "mediumtext"
l!l&&r!l&&!r
491151
$type eq "text" or $type eq "clob" or $type eq "long"
l!l&&r!l&&!r
490152
$type eq "text" or $type eq "clob"
l!l&&r!l&&!r
490152
MC/DC60%3/5
$type eq "text" or $type eq "clob" or $type eq "long" or $type eq "mediumtext" or $type eq "longtext"
$type eq "text" $type eq "clob" $type eq "long" $type eq "mediumtext" $type eq "longtext"
Truth table66%4/6
A or B or C or D or E
A= $type eq "text"B= $type eq "clob"C= $type eq "long"D= $type eq "mediumtext"E= $type eq "longtext"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
82 if $type eq 'text' || $type eq 'clob' || $type eq 'long' || $type eq 'mediumtext' || $type eq 'longtext';
83 150 ▶ return 'DATE' if $type eq 'date';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "date" 3 147 150
84 147 ▶ return 'TIMESTAMP' if $type eq 'datetime' || $type eq 'timestamp';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "datetime" or $type eq "timestamp" 13 134 147
Condition100%3/3
$type eq "datetime" or $type eq "timestamp"
l!l&&r!l&&!r
76134
MC/DC100%2/2
$type eq "datetime" or $type eq "timestamp"
$type eq "datetime" $type eq "timestamp"
Truth table100%3/3
A or B
A= $type eq "datetime"B= $type eq "timestamp"
ABresult
1X1
011
000
85 134 ▶ return 'TIMESTAMP WITH TIME ZONE' if $type eq 'timestamptz';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "timestamptz" 0 134 134
86 134 ▶ return 'DOUBLE PRECISION' if $type eq 'double precision' || $type eq 'double' || $type eq 'float' || $type eq 'real';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "double precision" or $type eq "double" or $type eq "float" or $type eq "real" 63 71 134
Condition100%9/9
$type eq "double precision" or $type eq "double" or $type eq "float" or $type eq "real"
l!l&&r!l&&!r
422171
$type eq "double precision" or $type eq "double" or $type eq "float"
l!l&&r!l&&!r
222092
$type eq "double precision" or $type eq "double"
l!l&&r!l&&!r
121112
MC/DC100%4/4
$type eq "double precision" or $type eq "double" or $type eq "float" or $type eq "real"
$type eq "double precision" $type eq "double" $type eq "float" $type eq "real"
Truth table100%5/5
A or B or C or D
A= $type eq "double precision"B= $type eq "double"C= $type eq "float"D= $type eq "real"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
87 71 ▶ return 'DECIMAL' . (render_size($size) || '(18,6)') if $type eq 'numeric' || $type eq 'decimal';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "numeric" or $type eq "decimal" 63 8 71
Condition100%5/5
$type eq "numeric" or $type eq "decimal"
l!l&&r!l&&!r
36278
render_size($size) || '(18,6)'
l!l
1548
MC/DC100%2/2
$type eq "numeric" or $type eq "decimal"
$type eq "numeric" $type eq "decimal"
MC/DC100%1/1
render_size($size) || '(18,6)'
render_size($size)
Truth table100%3/3
A or B
A= $type eq "numeric"B= $type eq "decimal"
ABresult
1X1
011
000
Truth table100%2/2
A
A= render_size($size)
Aresult
11
00
88 8 ▶ return 'BOOLEAN' if is_boolean_type($type);
Branch: 1 branch
BranchTrueFalseTotal
if is_boolean_type($type) 7 1 8
89 1 return uc($type);
90 }
91  
92  
93 520 ▶sub is_boolean_type {
Subroutine is_boolean_type: called CC=3 SCAR=11.0
Pod documented
94 520 my ($data_type) = @_;
95 520 ▶ return 0 unless defined $data_type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_type 12 508 520
96 508 ▶ return lc($data_type) =~ /\A(?:boolean|bool)\z/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
lc($data_type) =~ /\A(?:boolean|bool)\z/ ? : 131 377 508
97 }
98  
99  
100 18 ▶sub is_binary_type {
Subroutine is_binary_type: called CC=3 SCAR=11.0
Pod documented
101 18 my ($data_type) = @_;
102 18 ▶ return 0 unless defined $data_type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_type 2 16 18
103 16 ▶ return ddl_type_from_info({ data_type => $data_type }) =~ /\A(?:BLOB\z|BINARY\b|VARBINARY\b)/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
ddl_type_from_info({'data_type', $data_type}) =~ /\A(?:BLOB\z|BINARY\b|VARBINARY\b)/ ? : 4 12 16
104 }
105  
106  
107 362 ▶sub is_numeric_type {
Subroutine is_numeric_type: called CC=3 SCAR=11.0
Pod documented
108 362 my ($data_type) = @_;
109 362 ▶ return 0 unless defined $data_type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_type 6 356 362
110 356 ▶ return ddl_type_from_info({ data_type => $data_type }) =~ /\A(?:SMALLINT|INTEGER|BIGINT|DECIMAL|DOUBLE PRECISION)\b/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
ddl_type_from_info({'data_type', $data_type}) =~ /\A(?:SMALLINT|INTEGER|BIGINT|DECIMAL|DOUBLE PRECISION)\b/ ? : 306 50 356
111 }
112  
113  
114 54 ▶sub lob_kind {
Subroutine lob_kind: called CC=4 SCAR=13.9
Pod documented
115 54 my ($data_type, $size) = @_;
116 54 ▶ return undef unless defined $data_type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_type 0 54 54
117 54 my $ddl = ddl_type_from_info({ data_type => $data_type, size => $size });
118 54 ▶ return $ddl eq 'BLOB SUB_TYPE TEXT' ? 'text'
Branch: 2 branches
BranchTrueFalseTotal
$ddl eq 'BLOB SUB_TYPE TEXT' ? : 26 28 54
$ddl eq 'BLOB' ? : 6 22 28
119 : $ddl eq 'BLOB' ? 'binary'
120 : undef;
121 }
122  
123  
124 419 ▶sub render_size {
Subroutine render_size: called CC=3 SCAR=11.0
Pod documented
125 419 my ($size) = @_;
126 419 ▶ return '' unless defined $size;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size 211 208 419
127 208 ▶ return "($size->[0],$size->[1])" if ref $size eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $size eq "ARRAY" 47 161 208
128 161 return "($size)";
129 }
130  
131 43 1;
132  
133 __END__
« Firebird/Diff/Constraint.pm ↑ Summary Firebird/Storage/InterBase.pm »