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