DBIx/Class/Storage/DBI/Firebird/Common.pm

filter: Statementstmt 35.6% 26 / 73 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 33.3% 6 / 18 Podpod 100% 1 / 1 totaltotal 25.0% 33 / 132 CC 15 SCAR 30.7
CC
15
Cov
25%
_dbh_get_autoinc_seq
72.0
_sequence_fetch
12.0
__ANON__
6.0
CRAP 21.5
« DBIx/Class/ResultSource/RowParser.pm ↑ Summary DBIx/Class/Storage/DBI/SQLAnywhere/Cursor.pm »
1 package DBIx::Class::Storage::DBI::Firebird::Common;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use base qw/DBIx::Class::Storage::DBI/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 DBIx::Class::Storage::DBI::Firebird::Common - Driver Base Class for the Firebird RDBMS
13  
14 =head1 DESCRIPTION
15  
16 This class implements autoincrements for Firebird using C<RETURNING> as well as
17 L<auto_nextval|DBIx::Class::ResultSource/auto_nextval>, savepoints and server
18 version detection.
19  
20 =cut
21  
22 # set default
23 2 __PACKAGE__->_use_insert_returning (1);
24 2 __PACKAGE__->sql_limit_dialect ('FirstSkip');
25 2 __PACKAGE__->sql_quote_char ('"');
26  
27 2 __PACKAGE__->datetime_parser_type(
28 'DBIx::Class::Storage::DBI::InterBase::DateTime::Format'
29 );
30  
31 sub sqlt_type {
32 0 ▶ return 'Firebird';
Subroutine sqlt_type: not called CC=1 SCAR=6.9
Pod documented
33 }
34  
35 sub _sequence_fetch {
36 0 ▶ my ($self, $nextval, $sequence) = @_;
Subroutine _sequence_fetch: not called CC=3 SCAR=24.8
37  
38 0 ▶ $self->throw_exception("Can only fetch 'nextval' for a sequence")
Branch: 1 branch
BranchTrueFalseTotal
unless $nextval =~ /^nextval$/i 0 0 0
39 if $nextval !~ /^nextval$/i;
40  
41 0 ▶ $self->throw_exception('No sequence to fetch') unless $sequence;
Branch: 1 branch
BranchTrueFalseTotal
unless $sequence 0 0 0
42  
43 0 my ($val) = $self->_get_dbh->selectrow_array(sprintf
44 'SELECT GEN_ID(%s, 1) FROM rdb$database',
45 $self->sql_maker->_quote($sequence)
46 );
47  
48 0 return $val;
49 }
50  
51 sub _dbh_get_autoinc_seq {
52 0 ▶ my ($self, $dbh, $source, $col) = @_;
Subroutine _dbh_get_autoinc_seq: not called CC=8 SCAR=42.8
53  
54 0 my $table_name = $source->from;
55 0 ▶ $table_name = $$table_name if ref $table_name;
Branch: 1 branch
BranchTrueFalseTotal
if ref $table_name 0 0 0
56 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
57  
58 0 local $dbh->{LongReadLen} = 100000;
59 0 local $dbh->{LongTruncOk} = 1;
60  
61 0 my $sth = $dbh->prepare(<<'EOF');
62 SELECT t.rdb$trigger_source
63 FROM rdb$triggers t
64 WHERE t.rdb$relation_name = ?
65 AND t.rdb$system_flag = 0 -- user defined
66 AND t.rdb$trigger_type = 1 -- BEFORE INSERT
67 EOF
68 0 $sth->execute($table_name);
69  
70 0 ▶ while (my ($trigger) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($trigger) = $sth->fetchrow_array) 0 0 0
71 my @trig_cols = map
72 0 ▶ { /^"([^"]+)/ ? $1 : uc($_) }
Branch: 1 branch
BranchTrueFalseTotal
/^"([^"]+)/ ? : 0 0 0
73 $trigger =~ /new\.("?\w+"?)/ig
74 ;
75  
76 0 my ($quoted, $generator) = $trigger =~
77 /(?:gen_id\s* \( \s* |next \s* value \s* for \s*)(")?(\w+)/ix;
78  
79 0 ▶ if ($generator) {
Branch: 1 branch
BranchTrueFalseTotal
if ($generator) 0 0 0
80 0 ▶ $generator = uc $generator unless $quoted;
Branch: 1 branch
BranchTrueFalseTotal
unless $quoted 0 0 0
81  
82 return $generator
83 if first {
84 0 ▶ $self->sql_maker->quote_char ? ($_ eq $col) : (uc($_) eq uc($col))
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$self->sql_maker->quote_char ? : 0 0 0
85 0 ▶ } @trig_cols;
Branch: 1 branch
BranchTrueFalseTotal
if &first(sub { $self->sql_maker->quote_char ? $_ eq $col : uc $_ eq uc $col; } , @trig_cols) 0 0 0
86 }
87 }
88  
89 0 return undef;
90 }
91  
92 sub _exec_svp_begin {
93 0 ▶ my ($self, $name) = @_;
Subroutine _exec_svp_begin: not called CC=1 SCAR=6.9
94  
95 0 $self->_dbh->do("SAVEPOINT $name");
96 }
97  
98 sub _exec_svp_release {
99 0 ▶ my ($self, $name) = @_;
Subroutine _exec_svp_release: not called CC=1 SCAR=6.9
100  
101 0 $self->_dbh->do("RELEASE SAVEPOINT $name");
102 }
103  
104 sub _exec_svp_rollback {
105 0 ▶ my ($self, $name) = @_;
Subroutine _exec_svp_rollback: not called CC=1 SCAR=6.9
106  
107 0 $self->_dbh->do("ROLLBACK TO SAVEPOINT $name")
108 }
109  
110 # http://www.firebirdfaq.org/faq223/
111 sub _get_server_version {
112 0 ▶ my $self = shift;
Subroutine _get_server_version: not called CC=1 SCAR=6.9
113  
114 0 return $self->_get_dbh->selectrow_array(q{
115 SELECT rdb$get_context('SYSTEM', 'ENGINE_VERSION') FROM rdb$database
116 });
117 }
118  
119 package # hide from PAUSE
120 DBIx::Class::Storage::DBI::InterBase::DateTime::Format;
121  
122 2 my $timestamp_format = '%Y-%m-%d %H:%M:%S.%4N'; # %F %T
123 2 my $date_format = '%Y-%m-%d';
124  
125 2 my ($timestamp_parser, $date_parser);
126  
127 sub parse_datetime {
128 0 ▶ shift;
Subroutine parse_datetime: not called CC=2 SCAR=17.9
129 0 require DateTime::Format::Strptime;
130 0 ▶ $timestamp_parser ||= DateTime::Format::Strptime->new(
Condition0%0/3
$timestamp_parser ||= "DateTime::Format::Strptime"->new("pattern", $timestamp_format, "on_error", "croak")
l!l&&r!l&&!r
000
MC/DC0%0/2
$timestamp_parser ||= "DateTime::Format::Strptime"->new("pattern", $timestamp_format, "on_error", "croak")
$timestamp_parser "DateTime::Format::Strptime"->new("pattern", $timestamp_format, "on_error", "croak")
Truth table0%0/3
A ||= B
A= $timestamp_parserB= "DateTime::Format::Strptime"->new("pattern", $timestamp_format, "on_error", "croak")
ABresult
1X1
011
000
131 pattern => $timestamp_format,
132 on_error => 'croak',
133 );
134 0 return $timestamp_parser->parse_datetime(shift);
135 }
136  
137 sub format_datetime {
138 0 ▶ shift;
Subroutine format_datetime: not called CC=2 SCAR=17.9
139 0 require DateTime::Format::Strptime;
140 0 ▶ $timestamp_parser ||= DateTime::Format::Strptime->new(
Condition0%0/3
$timestamp_parser ||= "DateTime::Format::Strptime"->new("pattern", $timestamp_format, "on_error", "croak")
l!l&&r!l&&!r
000
MC/DC0%0/2
$timestamp_parser ||= "DateTime::Format::Strptime"->new("pattern", $timestamp_format, "on_error", "croak")
$timestamp_parser "DateTime::Format::Strptime"->new("pattern", $timestamp_format, "on_error", "croak")
Truth table0%0/3
A ||= B
A= $timestamp_parserB= "DateTime::Format::Strptime"->new("pattern", $timestamp_format, "on_error", "croak")
ABresult
1X1
011
000
141 pattern => $timestamp_format,
142 on_error => 'croak',
143 );
144 0 return $timestamp_parser->format_datetime(shift);
145 }
146  
147 sub parse_date {
148 0 ▶ shift;
Subroutine parse_date: not called CC=2 SCAR=17.9
149 0 require DateTime::Format::Strptime;
150 0 ▶ $date_parser ||= DateTime::Format::Strptime->new(
Condition0%0/3
$date_parser ||= "DateTime::Format::Strptime"->new("pattern", $date_format, "on_error", "croak")
l!l&&r!l&&!r
000
MC/DC0%0/2
$date_parser ||= "DateTime::Format::Strptime"->new("pattern", $date_format, "on_error", "croak")
$date_parser "DateTime::Format::Strptime"->new("pattern", $date_format, "on_error", "croak")
Truth table0%0/3
A ||= B
A= $date_parserB= "DateTime::Format::Strptime"->new("pattern", $date_format, "on_error", "croak")
ABresult
1X1
011
000
151 pattern => $date_format,
152 on_error => 'croak',
153 );
154 0 return $date_parser->parse_datetime(shift);
155 }
156  
157 sub format_date {
158 0 ▶ shift;
Subroutine format_date: not called CC=2 SCAR=17.9
159 0 require DateTime::Format::Strptime;
160 0 ▶ $date_parser ||= DateTime::Format::Strptime->new(
Condition0%0/3
$date_parser ||= "DateTime::Format::Strptime"->new("pattern", $date_format, "on_error", "croak")
l!l&&r!l&&!r
000
MC/DC0%0/2
$date_parser ||= "DateTime::Format::Strptime"->new("pattern", $date_format, "on_error", "croak")
$date_parser "DateTime::Format::Strptime"->new("pattern", $date_format, "on_error", "croak")
Truth table0%0/3
A ||= B
A= $date_parserB= "DateTime::Format::Strptime"->new("pattern", $date_format, "on_error", "croak")
ABresult
1X1
011
000
161 pattern => $date_format,
162 on_error => 'croak',
163 );
164 0 return $date_parser->format_datetime(shift);
165 }
166  
167 2 1;
168  
169 =head1 CAVEATS
170  
171 =over 4
172  
173 =item *
174  
175 C<last_insert_id> support by default only works for Firebird versions 2 or
176 greater, L<auto_nextval|DBIx::Class::ResultSource/auto_nextval> however should
177 work with earlier versions.
178  
179 =back
180  
181 =head1 AUTHOR
182  
183 See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
184  
185 =head1 LICENSE
186  
187 You may distribute this code under the same terms as Perl itself.
188  
189 =cut
190 # vim:sts=2 sw=2:
« DBIx/Class/ResultSource/RowParser.pm ↑ Summary DBIx/Class/Storage/DBI/SQLAnywhere/Cursor.pm »