Firebird/Storage/Common.pm

filter: Statementstmt 34.0% 16 / 47 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 36.3% 4 / 11 Podpod 100% 1 / 1 totaltotal 26.5% 21 / 79 CC 11 SCAR 37.1
CC
11
Cov
24%
_dbh_get_autoinc_seq
90.0
_sequence_fetch
12.0
sqlt_type
2.0
CRAP 41.0
« Firebird/Introspect/Indexes.pm ↑ Summary Firebird/Introspect/ForeignKeys.pm »
1 package DBIO::Firebird::Storage::Common;
2 # ABSTRACT: Shared Firebird / InterBase storage logic
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use base qw/DBIO::Storage::DBI/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 2 __PACKAGE__->_use_insert_returning (1);
11 2 __PACKAGE__->sql_quote_char ('"');
12 2 __PACKAGE__->sql_maker_class ('DBIO::Firebird::SQLMaker');
13  
14 0 ▶sub sqlt_type {
Subroutine sqlt_type: not called CC=1 SCAR=6.9
Pod documented
15 0 return 'Firebird';
16 }
17  
18  
19 0 ▶sub _sequence_fetch {
Subroutine _sequence_fetch: not called CC=3 SCAR=24.8
20 0 my ($self, $nextval, $sequence) = @_;
21  
22 0 ▶ $self->throw_exception("Can only fetch 'nextval' for a sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless $nextval =~ /^nextval$/i 0 0 0
23 if $nextval !~ /^nextval$/i;
24  
25 0 ▶ $self->throw_exception('No sequence to fetch') unless $sequence;
Branch: 1 branch
BranchTrueFalseTotal
unless $sequence 0 0 0
26  
27 0 my ($val) = $self->_get_dbh->selectrow_array(sprintf
28 'SELECT GEN_ID(%s, 1) FROM rdb$database',
29 $self->sql_maker->_quote($sequence)
30 );
31  
32 0 return $val;
33 }
34  
35 0 ▶sub _dbh_get_autoinc_seq {
Subroutine _dbh_get_autoinc_seq: not called CC=9 SCAR=45.0
36 0 my ($self, $dbh, $source, $col) = @_;
37  
38 0 my $table_name = $source->from;
39 0 ▶ $table_name = $$table_name if ref $table_name;
Branch: 1 branch
BranchTrueFalseTotal
if ref $table_name 0 0 0
40 0 ▶ $table_name = $self->sql_maker->quote_char ? $table_name : uc($table_name);
Branch: 1 branch
BranchTrueFalseTotal
$self->sql_maker->quote_char ? : 0 0 0
41  
42 0 local $dbh->{LongReadLen} = 100000;
43 0 local $dbh->{LongTruncOk} = 1;
44  
45 0 my $sth = $dbh->prepare(<<'EOF');
46 SELECT t.rdb$trigger_source
47 FROM rdb$triggers t
48 WHERE t.rdb$relation_name = ?
49 AND t.rdb$system_flag = 0 -- user defined
50 AND t.rdb$trigger_type = 1 -- BEFORE INSERT
51 EOF
52 0 $sth->execute($table_name);
53  
54 0 ▶ while (my ($trigger) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($trigger) = $sth->fetchrow_array) 0 0 0
55 my @trig_cols = map
56 0 ▶ { /^"([^"]+)/ ? $1 : uc($_) }
Branch: 1 branch
BranchTrueFalseTotal
/^"([^"]+)/ ? : 0 0 0
57 $trigger =~ /new\.("?\w+"?)/ig
58 ;
59  
60 0 my ($quoted, $generator) = $trigger =~
61 /(?:gen_id\s* \( \s* |next \s* value \s* for \s*)(")?(\w+)/ix;
62  
63 0 ▶ if ($generator) {
Branch: 1 branch
BranchTrueFalseTotal
if ($generator) 0 0 0
64 0 ▶ $generator = uc $generator unless $quoted;
Branch: 1 branch
BranchTrueFalseTotal
unless $quoted 0 0 0
65  
66 return $generator
67 if grep {
68 0 ▶ $self->sql_maker->quote_char ? ($_ eq $col) : (uc($_) eq uc($col))
Branch: 2 branches
BranchTrueFalseTotal
if grep {$self->sql_maker->quote_char ? $_ eq $col : uc $_ eq uc $col;} @trig_cols 0 0 0
$self->sql_maker->quote_char ? : 0 0 0
69 } @trig_cols;
70 }
71 }
72  
73 0 return undef;
74 }
75  
76 0 ▶sub _exec_svp_begin {
Subroutine _exec_svp_begin: not called CC=1 SCAR=6.9
77 0 my ($self, $name) = @_;
78  
79 0 $self->_dbh->do("SAVEPOINT $name");
80 }
81  
82 0 ▶sub _exec_svp_release {
Subroutine _exec_svp_release: not called CC=1 SCAR=6.9
83 0 my ($self, $name) = @_;
84  
85 0 $self->_dbh->do("RELEASE SAVEPOINT $name");
86 }
87  
88 0 ▶sub _exec_svp_rollback {
Subroutine _exec_svp_rollback: not called CC=1 SCAR=6.9
89 0 my ($self, $name) = @_;
90  
91 0 $self->_dbh->do("ROLLBACK TO SAVEPOINT $name")
92 }
93  
94 # http://www.firebirdfaq.org/faq223/
95 0 ▶sub _get_server_version {
Subroutine _get_server_version: not called CC=1 SCAR=6.9
96 0 my $self = shift;
97  
98 0 return $self->_get_dbh->selectrow_array(q{
99 SELECT rdb$get_context('SYSTEM', 'ENGINE_VERSION') FROM rdb$database
100 });
101 }
102  
103  
104 2 1;
105  
106 __END__
107  
108 =pod
109  
110 =encoding UTF-8
111  
112 =head1 NAME
113  
114 DBIO::Firebird::Storage::Common - Shared Firebird / InterBase storage logic
115  
116 =head1 VERSION
117  
118 version 0.900001
119  
120 =head1 DESCRIPTION
121  
122 This class contains the shared logic for both Firebird and InterBase drivers.
123 It extends L<DBIO::Storage::DBI> directly to avoid unnecessary inheritance depth.
124  
125 =head1 METHODS
126  
127 =head2 sqlt_type
128  
129 Returns C<Firebird>, identifying this storage to L<SQL::Translator>.
130  
131 =head1 CAVEATS
132  
133 =over 4
134  
135 =item *
136  
137 C<last_insert_id> support by default only works for Firebird versions 2 or
138 greater, L<auto_nextval|DBIO::ResultSource/auto_nextval> however should
139 work with earlier versions.
140  
141 =back
142  
143 =head1 SEE ALSO
144  
145 =over
146  
147 =item * L<DBIO::Firebird> - Firebird schema component
148  
149 =item * L<DBIO::Firebird::Storage> - Firebird driver via L<DBD::Firebird>
150  
151 =item * L<DBIO::Firebird::Storage::InterBase> - InterBase driver
152  
153 =item * L<DBIO::Storage::DBI> - Base DBI storage class
154  
155 =back
156  
157 =head1 AUTHOR
158  
159 DBIO & DBIx::Class Authors
160  
161 =head1 COPYRIGHT AND LICENSE
162  
163 Copyright (C) 2026 DBIO Authors
164 Portions Copyright (C) 2005-2025 DBIx::Class Authors
165 Based on DBIx::Class, heavily modified.
166  
167 This is free software; you can redistribute it and/or modify it under
168 the same terms as the Perl 5 programming language system itself.
169  
170 =cut
« Firebird/Introspect/Indexes.pm ↑ Summary Firebird/Introspect/ForeignKeys.pm »