| 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"
MC/DC100%1/1
$RDB_TYPE{$type_num} // "varchar"
$RDB_TYPE{$type_num}
Truth table100%2/2
A
A= $RDB_TYPE{$type_num}
| |||||||||||||||||||||||||||||||||||||||||||
| 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"
MC/DC100%1/1
$info->{"data_type"} // "varchar"
$info->{"data_type"}
Truth table100%2/2
A
A= $info->{"data_type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 10 | ▶ | return 'INTEGER' if $type eq 'integer' || $type eq 'bigint' || $type eq 'smallint'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$type eq "integer" or $type eq "bigint" or $type eq "smallint"
$type eq "integer" or $type eq "bigint"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 8 | ▶ | return 'BIGINT' if $type eq 'bigserial' || $type eq 'serial'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type eq "bigserial" or $type eq "serial"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 7 | ▶ | return 'VARCHAR(255)' if $type eq 'varchar' || $type eq 'nvarchar'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type eq "varchar" or $type eq "nvarchar"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 5 | ▶ | return 'CHAR(1)' if $type eq 'char' || $type eq 'nchar'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type eq "char" or $type eq "nchar"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 5 | ▶ | return 'BLOB' if $type eq 'bytea' || $type eq 'blob'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type eq "bytea" or $type eq "blob"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 5 | ▶ | return 'BLOB SUB_TYPE TEXT' if $type eq 'text' || $type eq 'clob' || $type eq 'long'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$type eq "text" or $type eq "clob" or $type eq "long"
$type eq "text" or $type eq "clob"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | ▶ | return 'DATE' if $type eq 'date' || $type eq 'datetime' || $type eq 'timestamp'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$type eq "date" or $type eq "datetime" or $type eq "timestamp"
$type eq "date" or $type eq "datetime"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | ▶ | return 'DOUBLE PRECISION' if $type eq 'double precision' || $type eq 'float'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type eq "double precision" or $type eq "float"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | ▶ | return 'DECIMAL(18,6)' if $type eq 'numeric' || $type eq 'decimal'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type eq "numeric" or $type eq "decimal"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | ▶ | return 'SMALLINT' if $type eq 'boolean'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | ▶ | return "($size->[0],$size->[1])" if ref $size eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||||||||