Firebird/Type.pm

filter: Statementstmt 100% 31 / 31 Branchbran 87.5% 21 / 24 Conditioncond 62.5% 25 / 40 MC/DCmcdc 39.1% 9 / 23 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 3 totaltotal 72.4% 92 / 127 CC 27 SCAR 32.4
CC
27
Cov
81%
ddl_type_from_info
33.4
render_size
3.0
sql_type_from_rdb
2.0
CRAP 25.5
« Firebird/Introspect/ForeignKeys.pm ↑ Summary Firebird/Diff/Column.pm »
1 package DBIO::Firebird::Type;
2 # ABSTRACT: Firebird type-system mapping (introspection + DDL directions)
3  
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 our @EXPORT_OK = qw(sql_type_from_rdb ddl_type_from_info render_size);
10  
11  
12 # rdb$field_type number -> bare SQL type name (no size/precision; size is
13 # carried separately in the introspected model). $sub_type is accepted for
14 # forward compatibility (blob text vs binary distinction) but not yet used.
15 6 my %RDB_TYPE = (
16 7 => 'smallint',
17 8 => 'integer',
18 9 => 'bigint',
19 10 => 'float',
20 12 => 'date',
21 13 => 'time',
22 14 => 'timestamp',
23 16 => 'decimal',
24 21 => 'quad',
25 27 => 'double precision',
26 35 => 'timestamp', # legacy
27 37 => 'varchar',
28 40 => 'cstring',
29 261 => 'blob sub_type text',
30 270 => 'blob',
31 );
32  
33  
34 9 ▶sub sql_type_from_rdb {
Subroutine sql_type_from_rdb: called CC=2 SCAR=6.9
Pod undocumented
35 9 my ($type_num, $sub_type) = @_;
36 9 ▶ return $RDB_TYPE{$type_num} // 'varchar';
Condition100%2/2
$RDB_TYPE{$type_num} // "varchar"
l!l
81
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
37 }
38  
39  
40 10 ▶sub ddl_type_from_info {
Subroutine ddl_type_from_info: called CC=24 SCAR=35.1
Pod undocumented
41 10 my ($info) = @_;
42 10 ▶ my $type = lc($info->{data_type} // 'varchar');
Condition100%2/2
$info->{"data_type"} // "varchar"
l!l
91
MC/DC100%1/1
$info->{"data_type"} // "varchar"
$info->{"data_type"}
Truth table100%2/2
A
A= $info->{"data_type"}
Aresult
11
00
43 10 ▶ return 'INTEGER' if $type eq 'integer' || $type eq 'bigint' || $type eq 'smallint';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "integer" or $type eq "bigint" or $type eq "smallint" 2 8 10
Condition83%5/6
$type eq "integer" or $type eq "bigint" or $type eq "smallint"
l!l&&r!l&&!r
208
$type eq "integer" or $type eq "bigint"
l!l&&r!l&&!r
118
MC/DC66%2/3
$type eq "integer" or $type eq "bigint" or $type eq "smallint"
$type eq "integer" $type eq "bigint" $type eq "smallint"
Truth table75%3/4
A or B or C
A= $type eq "integer"B= $type eq "bigint"C= $type eq "smallint"
ABCresult
1XX1
01X1
0011
0000
44 8 ▶ return 'BIGINT' if $type eq 'bigserial' || $type eq 'serial';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "bigserial" or $type eq "serial" 1 7 8
Condition66%2/3
$type eq "bigserial" or $type eq "serial"
l!l&&r!l&&!r
017
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
45 7 ▶ return 'VARCHAR(255)' if $type eq 'varchar' || $type eq 'nvarchar';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "varchar" or $type eq "nvarchar" 2 5 7
Condition66%2/3
$type eq "varchar" or $type eq "nvarchar"
l!l&&r!l&&!r
205
MC/DC50%1/2
$type eq "varchar" or $type eq "nvarchar"
$type eq "varchar" $type eq "nvarchar"
Truth table66%2/3
A or B
A= $type eq "varchar"B= $type eq "nvarchar"
ABresult
1X1
011
000
46 5 ▶ return 'CHAR(1)' if $type eq 'char' || $type eq 'nchar';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "char" or $type eq "nchar" 0 5 5
Condition33%1/3
$type eq "char" or $type eq "nchar"
l!l&&r!l&&!r
005
MC/DC0%0/2
$type eq "char" or $type eq "nchar"
$type eq "char" $type eq "nchar"
Truth table33%1/3
A or B
A= $type eq "char"B= $type eq "nchar"
ABresult
1X1
011
000
47 5 ▶ return 'BLOB' if $type eq 'bytea' || $type eq 'blob';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "bytea" or $type eq "blob" 0 5 5
Condition33%1/3
$type eq "bytea" or $type eq "blob"
l!l&&r!l&&!r
005
MC/DC0%0/2
$type eq "bytea" or $type eq "blob"
$type eq "bytea" $type eq "blob"
Truth table33%1/3
A or B
A= $type eq "bytea"B= $type eq "blob"
ABresult
1X1
011
000
48 5 ▶ return 'BLOB SUB_TYPE TEXT' if $type eq 'text' || $type eq 'clob' || $type eq 'long';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "text" or $type eq "clob" or $type eq "long" 1 4 5
Condition66%4/6
$type eq "text" or $type eq "clob" or $type eq "long"
l!l&&r!l&&!r
104
$type eq "text" or $type eq "clob"
l!l&&r!l&&!r
104
MC/DC33%1/3
$type eq "text" or $type eq "clob" or $type eq "long"
$type eq "text" $type eq "clob" $type eq "long"
Truth table50%2/4
A or B or C
A= $type eq "text"B= $type eq "clob"C= $type eq "long"
ABCresult
1XX1
01X1
0011
0000
49 4 ▶ return 'DATE' if $type eq 'date' || $type eq 'datetime' || $type eq 'timestamp';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "date" or $type eq "datetime" or $type eq "timestamp" 1 3 4
Condition50%3/6
$type eq "date" or $type eq "datetime" or $type eq "timestamp"
l!l&&r!l&&!r
013
$type eq "date" or $type eq "datetime"
l!l&&r!l&&!r
004
MC/DC33%1/3
$type eq "date" or $type eq "datetime" or $type eq "timestamp"
$type eq "date" $type eq "datetime" $type eq "timestamp"
Truth table50%2/4
A or B or C
A= $type eq "date"B= $type eq "datetime"C= $type eq "timestamp"
ABCresult
1XX1
01X1
0011
0000
50 3 ▶ return 'DOUBLE PRECISION' if $type eq 'double precision' || $type eq 'float';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "double precision" or $type eq "float" 0 3 3
Condition33%1/3
$type eq "double precision" or $type eq "float"
l!l&&r!l&&!r
003
MC/DC0%0/2
$type eq "double precision" or $type eq "float"
$type eq "double precision" $type eq "float"
Truth table33%1/3
A or B
A= $type eq "double precision"B= $type eq "float"
ABresult
1X1
011
000
51 3 ▶ return 'DECIMAL(18,6)' if $type eq 'numeric' || $type eq 'decimal';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "numeric" or $type eq "decimal" 1 2 3
Condition66%2/3
$type eq "numeric" or $type eq "decimal"
l!l&&r!l&&!r
102
MC/DC50%1/2
$type eq "numeric" or $type eq "decimal"
$type eq "numeric" $type eq "decimal"
Truth table66%2/3
A or B
A= $type eq "numeric"B= $type eq "decimal"
ABresult
1X1
011
000
52 2 ▶ return 'SMALLINT' if $type eq 'boolean';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "boolean" 1 1 2
53 1 return uc($type);
54 }
55  
56  
57 12 ▶sub render_size {
Subroutine render_size: called CC=3 SCAR=11.0
Pod undocumented
58 12 my ($size) = @_;
59 12 ▶ return '' unless defined $size;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size 8 4 12
60 4 ▶ return "($size->[0],$size->[1])" if ref $size eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $size eq "ARRAY" 2 2 4
61 2 return "($size)";
62 }
63  
64 6 1;
65  
66 __END__
67  
68 =pod
69  
70 =encoding UTF-8
71  
72 =head1 NAME
73  
74 DBIO::Firebird::Type - Firebird type-system mapping (introspection + DDL directions)
75  
76 =head1 VERSION
77  
78 version 0.900001
79  
80 =head1 DESCRIPTION
81  
82 Single home for the Firebird type system. Three mappings used to live in three
83 modules pulling in different directions:
84  
85 =over 4
86  
87 =item * L<DBIO::Firebird::Introspect::Columns> mapped C<rdb$field_type> numbers
88 to SQL type names (the I<introspection> direction).
89  
90 =item * L<DBIO::Firebird::DDL> mapped DBIO/SQL::Translator C<data_type> values to
91 Firebird DDL types (the I<deploy> direction).
92  
93 =item * L<DBIO::Firebird::Diff::Table> rendered C<(size)> suffixes inline.
94  
95 =back
96  
97 Centralizing them removes a class of bug: introspection used to fold the size
98 into the type string (C<"decimal(18,6)">) I<and> set a separate C<size> field,
99 so C<Diff::Table> emitted the size twice (C<"decimal(18,6)(18,6)">). The
100 introspection mapping here returns the bare type; size is carried separately in
101 the model and rendered via L</render_size>.
102  
103 =func sql_type_from_rdb
104  
105 my $type = sql_type_from_rdb($field_type, $field_sub_type);
106  
107 Maps an C<rdb$field_type> number to a bare SQL type name (e.g. C<'integer'>,
108 C<'decimal'>). Unknown types fall back to C<'varchar'>.
109  
110 =func ddl_type_from_info
111  
112 my $ddl_type = ddl_type_from_info($column_info);
113  
114 Maps a DBIO / L<SQL::Translator> C<column_info> hashref to a concrete Firebird
115 DDL type string (e.g. C<'INTEGER'>, C<'VARCHAR(255)'>).
116  
117 =func render_size
118  
119 my $suffix = render_size($size); # "(255)", "(10,2)", or ""
120  
121 Renders a model C<size> field as a SQL size suffix. A scalar yields C<"(n)">,
122 an arrayref yields C<"(p,s)">, and C<undef> yields the empty string.
123  
124 =head1 AUTHOR
125  
126 DBIO & DBIx::Class Authors
127  
128 =head1 COPYRIGHT AND LICENSE
129  
130 Copyright (C) 2026 DBIO Authors
131 Portions Copyright (C) 2005-2025 DBIx::Class Authors
132 Based on DBIx::Class, heavily modified.
133  
134 This is free software; you can redistribute it and/or modify it under
135 the same terms as the Perl 5 programming language system itself.
136  
137 =cut
« Firebird/Introspect/ForeignKeys.pm ↑ Summary Firebird/Diff/Column.pm »