Firebird/Introspect.pm

filter: Statementstmt 73.5% 25 / 34 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod n/a totaltotal 76.7% 33 / 43 CC 1 SCAR 1.1
CC
1
Cov
74%
_build_model
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Firebird/Storage.pm ↑ Summary Firebird/Deploy.pm »
1 package DBIO::Firebird::Introspect;
2 # ABSTRACT: Introspect a Firebird database via rdb$ system tables
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  
7 3 ▶use base 'DBIO::Introspect::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 3 ▶use DBIO::Firebird::Introspect::Tables;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use DBIO::Firebird::Introspect::Columns;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use DBIO::Firebird::Introspect::Indexes;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use DBIO::Firebird::Introspect::Uniques;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use DBIO::Firebird::Introspect::ForeignKeys;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 0 ▶sub _build_model {
Subroutine _build_model: not called CC=1 SCAR=6.9
17 0 my ($self) = @_;
18 0 my $dbh = $self->dbh;
19  
20 # Firebird returns result-column names upper-cased; the helpers read
21 # lower-case rdb$ keys from fetchrow_hashref. Force lower-cased hash keys so
22 # the two agree (statement handles inherit this at prepare time).
23 0 local $dbh->{FetchHashKeyName} = 'NAME_lc';
24  
25 0 my $tables = DBIO::Firebird::Introspect::Tables->fetch($dbh);
26 0 my $columns = DBIO::Firebird::Introspect::Columns->fetch($dbh, $tables);
27 0 my $indexes = DBIO::Firebird::Introspect::Indexes->fetch($dbh, $tables);
28 0 my $uniques = DBIO::Firebird::Introspect::Uniques->fetch($dbh, $tables);
29 0 my $foreign_keys = DBIO::Firebird::Introspect::ForeignKeys->fetch($dbh, $tables);
30  
31 return {
32 0 tables => $tables,
33 columns => $columns,
34 indexes => $indexes,
35 unique_constraints => $uniques,
36 foreign_keys => $foreign_keys,
37 };
38 }
39  
40  
41 3 1;
42  
43 __END__
44  
45 =pod
46  
47 =encoding UTF-8
48  
49 =head1 NAME
50  
51 DBIO::Firebird::Introspect - Introspect a Firebird database via rdb$ system tables
52  
53 =head1 VERSION
54  
55 version 0.900001
56  
57 =head1 DESCRIPTION
58  
59 C<DBIO::Firebird::Introspect> reads the live state of a Firebird database
60 via the C<rdb$*> system tables and returns a unified model hashref. It is the
61 source side of the test-deploy-and-compare strategy used by
62 L<DBIO::Firebird::Deploy>.
63  
64 my $intro = DBIO::Firebird::Introspect->new(dbh => $dbh);
65 my $model = $intro->model;
66 # $model->{tables}, $model->{columns}, $model->{indexes},
67 # $model->{unique_constraints}, $model->{foreign_keys}
68  
69 The model is built lazily on first access and has five top-level sections:
70 tables, columns, indexes, unique_constraints, and foreign_keys (views are
71 surfaced within the tables section, not as a separate top-level key). On top
72 of it, this class implements the normalized
73 generation contract from L<DBIO::Introspect::Base> so it can act as a
74 L<DBIO::Generate> source.
75  
76 =head1 THE INTROSPECTED MODEL
77  
78 The model hashref returned by L</model> is the shared substrate of this
79 distribution: produced here by the C<Introspect::*> helpers, consumed by
80 L<DBIO::Firebird::Diff> (table/column/index comparison) and by the
81 L</NORMALIZED CONTRACT> methods below (the L<DBIO::Generate> source). It has
82 exactly five top-level sections — C<tables>, C<columns>, C<indexes>,
83 C<unique_constraints>, and C<foreign_keys> — each a hashref keyed by
84 I<table name> (Firebird has no schemas, so keys are bare, un-qualified
85 relation names).
86  
87 =head2 tables
88  
89 { $table_name => { table_name => $name, kind => 'table' | 'view' } }
90  
91 =head2 columns
92  
93 { $table_name => [ \%column, ... ] } # in rdb$field_position order
94  
95 Each column hashref:
96  
97 =over 4
98  
99 =item * C<column_name> — the column name.
100  
101 =item * C<data_type> — the I<bare> SQL type (e.g. C<'integer'>, C<'decimal'>,
102 C<'varchar'>). Size/precision is B<not> folded in here; it lives in C<size>.
103  
104 =item * C<size> — C<undef>, a scalar length (C<varchar>/C<char>), or an
105 C<[ precision, scale ]> pair (C<decimal>/C<numeric>). Rendered to SQL via
106 L<DBIO::Firebird::Type/render_size>.
107  
108 =item * C<not_null> — C<1> if the column is C<NOT NULL>, else C<0>
109 (from C<rdb$null_flag>).
110  
111 =item * C<default_value> — the column default expression, or C<undef>.
112  
113 =item * C<is_pk> / C<pk_position> — primary-key membership and 0-based position (C<rdb$field_position>).
114  
115 =back
116  
117 =head2 indexes
118  
119 { $table_name => { $index_name => { index_name, is_unique, columns => [...] } } }
120  
121 Indexes backed by C<PRIMARY KEY> / C<UNIQUE> constraints are B<excluded> —
122 they belong to the table definition, not an explicit C<CREATE INDEX>.
123  
124 =head2 unique_constraints
125  
126 { $table_name => [ [ $constraint_name, \@column_names ], ... ] }
127  
128 C<UNIQUE> I<constraints> (distinct from the C<CREATE UNIQUE INDEX> objects in
129 C<indexes>), sorted by constraint name. Source of the C<table_uniq_info>
130 contract method.
131  
132 =head2 foreign_keys
133  
134 { $table_name => [ \%fk, ... ] }
135  
136 Each FK hashref: C<fk_id>, C<from_table>, C<from_columns>, C<to_table>,
137 C<to_columns>, and the referential actions C<on_update>, C<on_delete>,
138 C<match> (from C<rdb$ref_constraints>).
139  
140 =head1 NORMALIZED CONTRACT
141  
142 The L<DBIO::Generate> generation contract (C<table_keys>, C<table_columns>,
143 C<table_columns_info>, C<table_pk_info>, C<table_uniq_info>, C<table_fk_info>,
144 C<table_is_view>) is B<inherited unchanged> from L<DBIO::Introspect::Base>:
145 the model built by L</_build_model> follows the canonical single-schema shape
146 (see L<DBIO::Introspect::Base/CANONICAL MODEL>) that those default
147 implementations read, so no Firebird-specific override is needed. In
148 particular C<unique_constraints> is the authoritative source for
149 C<table_uniq_info>, and FK C<remote_schema> is always C<undef> (Firebird has
150 no schemas).
151  
152 =seealso
153  
154 =over 4
155  
156 =item * L<DBIO::Firebird::Deploy> - uses this class to compare current and desired state
157  
158 =item * L<DBIO::Firebird::Diff> - compares two models produced by this class
159  
160 =back
161  
162 =head1 AUTHOR
163  
164 DBIO & DBIx::Class Authors
165  
166 =head1 COPYRIGHT AND LICENSE
167  
168 Copyright (C) 2026 DBIO Authors
169 Portions Copyright (C) 2005-2025 DBIx::Class Authors
170 Based on DBIx::Class, heavily modified.
171  
172 This is free software; you can redistribute it and/or modify it under
173 the same terms as the Perl 5 programming language system itself.
174  
175 =cut
« Firebird/Storage.pm ↑ Summary Firebird/Deploy.pm »