| 1 | package DBIx::Class::Storage::DBI::Oracle::Generic; | ||||||||||||||||||||||||||||||||||||||||||
| 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 | 3 | ▶ | use DBIx::Class::Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Scope::Guard (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Context::Preserve 'preserve_context'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | __PACKAGE__->sql_limit_dialect ('RowNum'); | |||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | __PACKAGE__->sql_quote_char ('"'); | |||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | __PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker::Oracle'); | |||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | __PACKAGE__->datetime_parser_type('DateTime::Format::Oracle'); | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub __cache_queries_with_max_lob_parts { 2 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__cache_queries_with_max_lob_parts: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | DBIx::Class::Storage::DBI::Oracle::Generic - Oracle Support for DBIx::Class | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | # In your result (table) classes | ||||||||||||||||||||||||||||||||||||||||||
| 27 | use base 'DBIx::Class::Core'; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | __PACKAGE__->add_columns({ id => { sequence => 'mysequence', auto_nextval => 1 } }); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | __PACKAGE__->set_primary_key('id'); | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # Somewhere in your Code | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # add some data to a table with a hierarchical relationship | ||||||||||||||||||||||||||||||||||||||||||
| 33 | $schema->resultset('Person')->create ({ | ||||||||||||||||||||||||||||||||||||||||||
| 34 | firstname => 'foo', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | lastname => 'bar', | ||||||||||||||||||||||||||||||||||||||||||
| 36 | children => [ | ||||||||||||||||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||||||||||||||||
| 38 | firstname => 'child1', | ||||||||||||||||||||||||||||||||||||||||||
| 39 | lastname => 'bar', | ||||||||||||||||||||||||||||||||||||||||||
| 40 | children => [ | ||||||||||||||||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||||||||||||||||
| 42 | firstname => 'grandchild', | ||||||||||||||||||||||||||||||||||||||||||
| 43 | lastname => 'bar', | ||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 46 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | firstname => 'child2', | ||||||||||||||||||||||||||||||||||||||||||
| 49 | lastname => 'bar', | ||||||||||||||||||||||||||||||||||||||||||
| 50 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 52 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # select from the hierarchical relationship | ||||||||||||||||||||||||||||||||||||||||||
| 55 | my $rs = $schema->resultset('Person')->search({}, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 'start_with' => { 'firstname' => 'foo', 'lastname' => 'bar' }, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 'connect_by' => { 'parentid' => { '-prior' => { -ident => 'personid' } }, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 'order_siblings_by' => { -asc => 'name' }, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # this will select the whole tree starting from person "foo bar", creating | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # following query: | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # SELECT | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # me.persionid me.firstname, me.lastname, me.parentid | ||||||||||||||||||||||||||||||||||||||||||
| 67 | # FROM | ||||||||||||||||||||||||||||||||||||||||||
| 68 | # person me | ||||||||||||||||||||||||||||||||||||||||||
| 69 | # START WITH | ||||||||||||||||||||||||||||||||||||||||||
| 70 | # firstname = 'foo' and lastname = 'bar' | ||||||||||||||||||||||||||||||||||||||||||
| 71 | # CONNECT BY | ||||||||||||||||||||||||||||||||||||||||||
| 72 | # parentid = prior personid | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # ORDER SIBLINGS BY | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # firstname ASC | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | This class implements base Oracle support. The subclass | ||||||||||||||||||||||||||||||||||||||||||
| 79 | L<DBIx::Class::Storage::DBI::Oracle::WhereJoins> is for C<(+)> joins in Oracle | ||||||||||||||||||||||||||||||||||||||||||
| 80 | versions before 9.0. | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub _determine_supports_insert_returning { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_determine_supports_insert_returning: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | # TODO find out which version supports the RETURNING syntax | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # 8i has it and earlier docs are a 404 on oracle.com | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | return 1 | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if $self->_server_info->{normalized_dbms_version} >= 8.001; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 3 | __PACKAGE__->_use_insert_returning_bound (1); | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub deployment_statements { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deployment_statements: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $self = shift;; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my ($schema, $type, $version, $dir, $sqltargs, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | $sqltargs ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$sqltargs ||= {}
MC/DC0%0/1
$sqltargs ||= {}
$sqltargs
Truth table0%0/2
A
A= $sqltargs
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not exists $sqltargs->{"producer_args"}{"oracle_version"} and my $dver = $self->_server_info->{"dbms_version"}
MC/DC0%0/2
not exists $sqltargs->{"producer_args"}{"oracle_version"} and my $dver = $self->_server_info->{"dbms_version"}
not exists $sqltargs->{"producer_args"}{"oracle_version"}
my $dver = $self->_server_info->{"dbms_version"}
Truth table0%0/3
not(A) and B
A= not exists $sqltargs->{"producer_args"}{"oracle_version"}B= my $dver = $self->_server_info->{"dbms_version"}
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | ! exists $sqltargs->{producer_args}{oracle_version} | ||||||||||||||||||||||||||||||||||||||||||
| 108 | and | ||||||||||||||||||||||||||||||||||||||||||
| 109 | my $dver = $self->_server_info->{dbms_version} | ||||||||||||||||||||||||||||||||||||||||||
| 110 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $sqltargs->{producer_args}{oracle_version} = $dver; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $self->next::method($schema, $type, $version, $dir, $sqltargs, @rest); | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub _dbh_last_insert_id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbh_last_insert_id: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my ($self, $dbh, $source, @columns) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my @ids = (); | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | foreach my $col (@columns) { | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | my $seq = ($source->column_info($col)->{sequence} ||= $self->get_autoinc_seq($source,$col)); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$source->column_info($col)->{"sequence"} ||= $self->get_autoinc_seq($source, $col)
MC/DC0%0/2
$source->column_info($col)->{"sequence"} ||= $self->get_autoinc_seq($source, $col)
$source->column_info($col)->{"sequence"}
$self->get_autoinc_seq($source, $col)
Truth table0%0/3
A ||= B
A= $source->column_info($col)->{"sequence"}B= $self->get_autoinc_seq($source, $col)
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $id = $self->_sequence_fetch( 'CURRVAL', $seq ); | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | push @ids, $id; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | return @ids; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub _dbh_get_autoinc_seq { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbh_get_autoinc_seq: not called CC=17 SCAR=57.2
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my ($self, $dbh, $source, $col) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my $sql_maker = $self->sql_maker; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | my ($ql, $qr) = map { $_ ? (quotemeta $_) : '' } $sql_maker->_quote_chars; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my $source_name; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if ( ref $source->name eq 'SCALAR' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $source_name = ${$source->name}; | |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | # the ALL_TRIGGERS match further on is case sensitive - thus uppercase | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # stuff unless it is already quoted | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | $source_name = uc ($source_name) if $source_name !~ /\"/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $source_name = $source->name; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | $source_name = uc($source_name) unless $ql; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | # trigger_body is a LONG | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | local $dbh->{LongReadLen} = 64 * 1024 if ($dbh->{LongReadLen} < 64 * 1024); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | # disable default bindtype | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | local $sql_maker->{bindtype} = 'normal'; | |||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | # look up the correct sequence automatically | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | my ( $schema, $table ) = $source_name =~ /( (?:${ql})? \w+ (?:${qr})? ) \. ( (?:${ql})? \w+ (?:${qr})? )/x; | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | # if no explicit schema was requested - use the default schema (which in the case of Oracle is the db user) | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | $schema ||= \'= USER'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$schema ||= \"= USER"
MC/DC0%0/1
$schema ||= \"= USER"
$schema
Truth table0%0/2
A
A= $schema
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | my ($sql, @bind) = $sql_maker->select ( | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$table || $source_name
MC/DC0%0/2
$table || $source_name
$table
$source_name
Truth table0%0/3
A || B
A= $tableB= $source_name
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 'ALL_TRIGGERS', | ||||||||||||||||||||||||||||||||||||||||||
| 161 | [qw/TRIGGER_BODY TABLE_OWNER TRIGGER_NAME/], | ||||||||||||||||||||||||||||||||||||||||||
| 162 | { | ||||||||||||||||||||||||||||||||||||||||||
| 163 | OWNER => $schema, | ||||||||||||||||||||||||||||||||||||||||||
| 164 | TABLE_NAME => $table || $source_name, | ||||||||||||||||||||||||||||||||||||||||||
| 165 | TRIGGERING_EVENT => { -like => '%INSERT%' }, # this will also catch insert_or_update | ||||||||||||||||||||||||||||||||||||||||||
| 166 | TRIGGER_TYPE => { -like => '%BEFORE%' }, # we care only about 'before' triggers | ||||||||||||||||||||||||||||||||||||||||||
| 167 | STATUS => 'ENABLED', | ||||||||||||||||||||||||||||||||||||||||||
| 168 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 169 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | # to find all the triggers that mention the column in question a simple | ||||||||||||||||||||||||||||||||||||||||||
| 172 | # regex grep since the trigger_body above is a LONG and hence not searchable | ||||||||||||||||||||||||||||||||||||||||||
| 173 | # via -like | ||||||||||||||||||||||||||||||||||||||||||
| 174 | my @triggers = ( map | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | { my %inf; @inf{qw/body schema name/} = @$_; \%inf } | |||||||||||||||||||||||||||||||||||||||||
| 176 | ( grep | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | { $_->[0] =~ /\:new\.${ql}${col}${qr} | \:new\.$col/xi } | |||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | @{ $dbh->selectall_arrayref( $sql, {}, @bind ) } | |||||||||||||||||||||||||||||||||||||||||
| 179 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 180 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | # extract all sequence names mentioned in each trigger, throw away | ||||||||||||||||||||||||||||||||||||||||||
| 183 | # triggers without apparent sequences | ||||||||||||||||||||||||||||||||||||||||||
| 184 | @triggers = map { | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my @seqs = $_->{body} =~ / ( [\.\w\"\-]+ ) \. nextval /xig; | |||||||||||||||||||||||||||||||||||||||||
| 186 | @seqs | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | ? { %$_, sequences => \@seqs } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | : () | ||||||||||||||||||||||||||||||||||||||||||
| 189 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 190 | } @triggers; | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my $chosen_trigger; | |||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | # if only one trigger matched things are easy | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if (@triggers == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | if ( @{$triggers[0]{sequences}} == 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $chosen_trigger = $triggers[0]; | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 201 | $self->throw_exception( sprintf ( | ||||||||||||||||||||||||||||||||||||||||||
| 202 | "Unable to introspect trigger '%s' for column '%s.%s' (references multiple sequences). " | ||||||||||||||||||||||||||||||||||||||||||
| 203 | . "You need to specify the correct 'sequence' explicitly in '%s's column_info.", | ||||||||||||||||||||||||||||||||||||||||||
| 204 | $triggers[0]{name}, | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | $source_name, | |||||||||||||||||||||||||||||||||||||||||
| 206 | $col, | ||||||||||||||||||||||||||||||||||||||||||
| 207 | $col, | ||||||||||||||||||||||||||||||||||||||||||
| 208 | ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | # got more than one matching trigger - see if we can narrow it down | ||||||||||||||||||||||||||||||||||||||||||
| 212 | elsif (@triggers > 1) { | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | my @candidates = grep | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | { $_->{body} =~ / into \s+ \:new\.$col /xi } | |||||||||||||||||||||||||||||||||||||||||
| 216 | @triggers | ||||||||||||||||||||||||||||||||||||||||||
| 217 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if (@candidates == 1 && @{$candidates[0]{sequences}} == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@candidates == 1 and @{$candidates[0]{"sequences"};} == 1
MC/DC0%0/2
@candidates == 1 and @{$candidates[0]{"sequences"};} == 1
@candidates == 1
@{$candidates[0]{"sequences"};} == 1
Truth table0%0/3
A and B
A= @candidates == 1B= @{$candidates[0]{"sequences"};} == 1
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | $chosen_trigger = $candidates[0]; | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 223 | $self->throw_exception( sprintf ( | ||||||||||||||||||||||||||||||||||||||||||
| 224 | "Unable to reliably select a BEFORE INSERT trigger for column '%s.%s' (possibilities: %s). " | ||||||||||||||||||||||||||||||||||||||||||
| 225 | . "You need to specify the correct 'sequence' explicitly in '%s's column_info.", | ||||||||||||||||||||||||||||||||||||||||||
| 226 | $source_name, | ||||||||||||||||||||||||||||||||||||||||||
| 227 | $col, | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ( join ', ', map { "'$_->{name}'" } @triggers ), | |||||||||||||||||||||||||||||||||||||||||
| 229 | $col, | ||||||||||||||||||||||||||||||||||||||||||
| 230 | ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | if ($chosen_trigger) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my $seq_name = $chosen_trigger->{sequences}[0]; | |||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | $seq_name = "$chosen_trigger->{schema}.$seq_name" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | unless $seq_name =~ /\./; | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | return \$seq_name if $seq_name =~ /\"/; # may already be quoted in-trigger | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | return $seq_name; | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $self->throw_exception( sprintf ( | |||||||||||||||||||||||||||||||||||||||||
| 245 | "No suitable BEFORE INSERT triggers found for column '%s.%s'. " | ||||||||||||||||||||||||||||||||||||||||||
| 246 | . "You need to specify the correct 'sequence' explicitly in '%s's column_info.", | ||||||||||||||||||||||||||||||||||||||||||
| 247 | $source_name, | ||||||||||||||||||||||||||||||||||||||||||
| 248 | $col, | ||||||||||||||||||||||||||||||||||||||||||
| 249 | $col, | ||||||||||||||||||||||||||||||||||||||||||
| 250 | )); | ||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | sub _sequence_fetch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sequence_fetch: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | my ( $self, $type, $seq ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | # use the maker to leverage quoting settings | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | my $sth = $self->_dbh->prepare_cached( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | $self->sql_maker->select('DUAL', [ ref $seq ? \"$$seq.$type" : "$seq.$type" ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 259 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $sth->execute; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my ($id) = $sth->fetchrow_array; | |||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | return $id; | |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | sub _ping { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ping: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | my $dbh = $self->_dbh or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | local $dbh->{RaiseError} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | local $dbh->{PrintError} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | return try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $dbh->do('select 1 from dual'); | |||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | 0; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | sub _dbh_execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbh_execute: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | #my ($self, $dbh, $sql, $bind, $bind_attrs) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my ($self, $sql, $bind) = @_[0,2,3]; | |||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | # Turn off sth caching for multi-part LOBs. See _prep_for_execute below | ||||||||||||||||||||||||||||||||||||||||||
| 287 | local $self->{disable_sth_caching} = 1 if grep { | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | ($_->[0]{_ora_lob_autosplit_part}||0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$_->[0]{'_ora_lob_autosplit_part'} || 0
MC/DC0%0/1
$_->[0]{'_ora_lob_autosplit_part'} || 0
$_->[0]{'_ora_lob_autosplit_part'}
Truth table0%0/2
A
A= $_->[0]{'_ora_lob_autosplit_part'}
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | > | ||||||||||||||||||||||||||||||||||||||||||
| 290 | (__cache_queries_with_max_lob_parts - 1) | ||||||||||||||||||||||||||||||||||||||||||
| 291 | } @$bind; | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | my $next = $self->next::can; | |||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | # if we are already in a txn we can't retry anything | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | return shift->$next(@_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | if $self->transaction_depth; | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | # cheat the blockrunner we are just about to create | ||||||||||||||||||||||||||||||||||||||||||
| 300 | # we do want to rerun things regardless of outer state | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | local $self->{_in_do_block}; | |||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | return DBIx::Class::Storage::BlockRunner->new( | ||||||||||||||||||||||||||||||||||||||||||
| 304 | storage => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 305 | wrap_txn => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | retry_handler => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | # ORA-01003: no statement parsed (someone changed the table somehow, | ||||||||||||||||||||||||||||||||||||||||||
| 308 | # invalidating your cursor.) | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$_[0]->failed_attempt_count == 1 and $_[0]->last_exception =~ /ORA-01003/ and my $dbh = $_[0]->storage->_dbh
$_[0]->failed_attempt_count == 1 and $_[0]->last_exception =~ /ORA-01003/
MC/DC0%0/3
$_[0]->failed_attempt_count == 1 and $_[0]->last_exception =~ /ORA-01003/ and my $dbh = $_[0]->storage->_dbh
$_[0]->failed_attempt_count == 1
$_[0]->last_exception =~ /ORA-01003/
my $dbh = $_[0]->storage->_dbh
Truth table0%0/4
A and B and C
A= $_[0]->failed_attempt_count == 1B= $_[0]->last_exception =~ /ORA-01003/C= my $dbh = $_[0]->storage->_dbh
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | $_[0]->failed_attempt_count == 1 | ||||||||||||||||||||||||||||||||||||||||||
| 311 | and | ||||||||||||||||||||||||||||||||||||||||||
| 312 | $_[0]->last_exception =~ /ORA-01003/ | ||||||||||||||||||||||||||||||||||||||||||
| 313 | and | ||||||||||||||||||||||||||||||||||||||||||
| 314 | my $dbh = $_[0]->storage->_dbh | ||||||||||||||||||||||||||||||||||||||||||
| 315 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | delete $dbh->{CachedKids}{$sql}; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | )->run( $next, @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | sub _dbh_execute_for_fetch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbh_execute_for_fetch: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | #my ($self, $sth, $tuple_status, @extra) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | # DBD::Oracle warns loudly on partial execute_for_fetch failures | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | local $_[1]->{PrintWarn} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | shift->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | =head2 get_autoinc_seq | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | Returns the sequence name for an autoincrement column | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | sub get_autoinc_seq { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_autoinc_seq: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my ($self, $source, $col) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $self->dbh_do('_dbh_get_autoinc_seq', $source, $col); | |||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | =head2 datetime_parser_type | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | This sets the proper DateTime::Format module for use with | ||||||||||||||||||||||||||||||||||||||||||
| 350 | L<DBIx::Class::InflateColumn::DateTime>. | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | =head2 connect_call_datetime_setup | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | Used as: | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | on_connect_call => 'datetime_setup' | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set the session nls | ||||||||||||||||||||||||||||||||||||||||||
| 359 | date, and timestamp values for use with L<DBIx::Class::InflateColumn::DateTime> | ||||||||||||||||||||||||||||||||||||||||||
| 360 | and the necessary environment variables for L<DateTime::Format::Oracle>, which | ||||||||||||||||||||||||||||||||||||||||||
| 361 | is used by it. | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | Maximum allowable precision is used, unless the environment variables have | ||||||||||||||||||||||||||||||||||||||||||
| 364 | already been set. | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | These are the defaults used: | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | $ENV{NLS_DATE_FORMAT} ||= 'YYYY-MM-DD HH24:MI:SS'; | ||||||||||||||||||||||||||||||||||||||||||
| 369 | $ENV{NLS_TIMESTAMP_FORMAT} ||= 'YYYY-MM-DD HH24:MI:SS.FF'; | ||||||||||||||||||||||||||||||||||||||||||
| 370 | $ENV{NLS_TIMESTAMP_TZ_FORMAT} ||= 'YYYY-MM-DD HH24:MI:SS.FF TZHTZM'; | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | To get more than second precision with L<DBIx::Class::InflateColumn::DateTime> | ||||||||||||||||||||||||||||||||||||||||||
| 373 | for your timestamps, use something like this: | ||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | use Time::HiRes 'time'; | ||||||||||||||||||||||||||||||||||||||||||
| 376 | my $ts = DateTime->from_epoch(epoch => time); | ||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | sub connect_call_datetime_setup { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect_call_datetime_setup: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | my $date_format = $ENV{NLS_DATE_FORMAT} ||= 'YYYY-MM-DD HH24:MI:SS'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{"NLS_DATE_FORMAT"} ||= "YYYY-MM-DD HH24:MI:SS"
MC/DC0%0/1
$ENV{"NLS_DATE_FORMAT"} ||= "YYYY-MM-DD HH24:MI:SS"
$ENV{"NLS_DATE_FORMAT"}
Truth table0%0/2
A
A= $ENV{"NLS_DATE_FORMAT"}
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | my $timestamp_format = $ENV{NLS_TIMESTAMP_FORMAT} ||= | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | 'YYYY-MM-DD HH24:MI:SS.FF'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{"NLS_TIMESTAMP_FORMAT"} ||= "YYYY-MM-DD HH24:MI:SS.FF"
MC/DC0%0/1
$ENV{"NLS_TIMESTAMP_FORMAT"} ||= "YYYY-MM-DD HH24:MI:SS.FF"
$ENV{"NLS_TIMESTAMP_FORMAT"}
Truth table0%0/2
A
A= $ENV{"NLS_TIMESTAMP_FORMAT"}
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | my $timestamp_tz_format = $ENV{NLS_TIMESTAMP_TZ_FORMAT} ||= | ||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | 'YYYY-MM-DD HH24:MI:SS.FF TZHTZM'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{"NLS_TIMESTAMP_TZ_FORMAT"} ||= "YYYY-MM-DD HH24:MI:SS.FF TZHTZM"
MC/DC0%0/1
$ENV{"NLS_TIMESTAMP_TZ_FORMAT"} ||= "YYYY-MM-DD HH24:MI:SS.FF TZHTZM"
$ENV{"NLS_TIMESTAMP_TZ_FORMAT"}
Truth table0%0/2
A
A= $ENV{"NLS_TIMESTAMP_TZ_FORMAT"}
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | $self->_do_query( | |||||||||||||||||||||||||||||||||||||||||
| 390 | "alter session set nls_date_format = '$date_format'" | ||||||||||||||||||||||||||||||||||||||||||
| 391 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | $self->_do_query( | |||||||||||||||||||||||||||||||||||||||||
| 393 | "alter session set nls_timestamp_format = '$timestamp_format'" | ||||||||||||||||||||||||||||||||||||||||||
| 394 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | $self->_do_query( | |||||||||||||||||||||||||||||||||||||||||
| 396 | "alter session set nls_timestamp_tz_format='$timestamp_tz_format'" | ||||||||||||||||||||||||||||||||||||||||||
| 397 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | ### Note originally by Ron "Quinn" Straight <quinnfazigu@gmail.org> | ||||||||||||||||||||||||||||||||||||||||||
| 401 | ### https://github.com/Perl5/DBIx-Class/commit/5db2758de6 | ||||||||||||||||||||||||||||||||||||||||||
| 402 | # | ||||||||||||||||||||||||||||||||||||||||||
| 403 | # Handle LOB types in Oracle. Under a certain size (4k?), you can get away | ||||||||||||||||||||||||||||||||||||||||||
| 404 | # with the driver assuming your input is the deprecated LONG type if you | ||||||||||||||||||||||||||||||||||||||||||
| 405 | # encode it as a hex string. That ain't gonna fly at larger values, where | ||||||||||||||||||||||||||||||||||||||||||
| 406 | # you'll discover you have to do what this does. | ||||||||||||||||||||||||||||||||||||||||||
| 407 | # | ||||||||||||||||||||||||||||||||||||||||||
| 408 | # This method had to be overridden because we need to set ora_field to the | ||||||||||||||||||||||||||||||||||||||||||
| 409 | # actual column, and that isn't passed to the call (provided by Storage) to | ||||||||||||||||||||||||||||||||||||||||||
| 410 | # bind_attribute_by_data_type. | ||||||||||||||||||||||||||||||||||||||||||
| 411 | # | ||||||||||||||||||||||||||||||||||||||||||
| 412 | # According to L<DBD::Oracle>, the ora_field isn't always necessary, but | ||||||||||||||||||||||||||||||||||||||||||
| 413 | # adding it doesn't hurt, and will save your bacon if you're modifying a | ||||||||||||||||||||||||||||||||||||||||||
| 414 | # table with more than one LOB column. | ||||||||||||||||||||||||||||||||||||||||||
| 415 | # | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | ▶ | sub _dbi_attrs_for_bind { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbi_attrs_for_bind: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | my ($self, $ident, $bind) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | my $attrs = $self->next::method($ident, $bind); | |||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | # Push the column name into all bind attrs, make sure to *NOT* write into | ||||||||||||||||||||||||||||||||||||||||||
| 422 | # the existing $attrs->[$idx]{..} hashref, as it is cached by the call to | ||||||||||||||||||||||||||||||||||||||||||
| 423 | # next::method above. | ||||||||||||||||||||||||||||||||||||||||||
| 424 | $attrs->[$_] | ||||||||||||||||||||||||||||||||||||||||||
| 425 | and | ||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | keys %{ $attrs->[$_] } | |||||||||||||||||||||||||||||||||||||||||
| 427 | and | ||||||||||||||||||||||||||||||||||||||||||
| 428 | $bind->[$_][0]{dbic_colname} | ||||||||||||||||||||||||||||||||||||||||||
| 429 | and | ||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | $attrs->[$_] = { %{$attrs->[$_]}, ora_field => $bind->[$_][0]{dbic_colname} } | |||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | for 0 .. $#$attrs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$attrs->[$_] and keys %{$$attrs[$_];} and $bind->[$_][0]{"dbic_colname"}
$attrs->[$_] and keys %{$$attrs[$_];}
MC/DC0%0/3
$attrs->[$_] and keys %{$$attrs[$_];} and $bind->[$_][0]{"dbic_colname"}
$attrs->[$_]
keys %{$$attrs[$_];}
$bind->[$_][0]{"dbic_colname"}
Truth table0%0/4
A and B and C
A= $attrs->[$_]B= keys %{$$attrs[$_];}C= $bind->[$_][0]{"dbic_colname"}
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $attrs; | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | sub bind_attribute_by_data_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind_attribute_by_data_type: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | my ($self, $dt) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | if ($self->_is_lob_type($dt)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | # this is a hot-ish codepath, store an escape-flag in the DBD namespace, so that | ||||||||||||||||||||||||||||||||||||||||||
| 442 | # things like Class::Unload work (unlikely but possible) | ||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | unless ($DBD::Oracle::__DBIC_DBD_VERSION_CHECK_OK__) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | # no earlier - no later | ||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | if ($DBD::Oracle::VERSION eq '1.23') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | $self->throw_exception( | |||||||||||||||||||||||||||||||||||||||||
| 448 | "BLOB/CLOB support in DBD::Oracle == 1.23 is broken, use an earlier or later ". | ||||||||||||||||||||||||||||||||||||||||||
| 449 | "version (https://rt.cpan.org/Public/Bug/Display.html?id=46016)" | ||||||||||||||||||||||||||||||||||||||||||
| 450 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | $DBD::Oracle::__DBIC_DBD_VERSION_CHECK_OK__ = 1; | |||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | ora_type => $self->_is_text_lob_type($dt) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | ? DBD::Oracle::ORA_CLOB() | ||||||||||||||||||||||||||||||||||||||||||
| 459 | : DBD::Oracle::ORA_BLOB() | ||||||||||||||||||||||||||||||||||||||||||
| 460 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||
| 462 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | # Handle blob columns in WHERE. | ||||||||||||||||||||||||||||||||||||||||||
| 468 | # | ||||||||||||||||||||||||||||||||||||||||||
| 469 | # For equality comparisons: | ||||||||||||||||||||||||||||||||||||||||||
| 470 | # | ||||||||||||||||||||||||||||||||||||||||||
| 471 | # We split data intended for comparing to a LOB into 2000 character chunks and | ||||||||||||||||||||||||||||||||||||||||||
| 472 | # compare them using dbms_lob.substr on the LOB column. | ||||||||||||||||||||||||||||||||||||||||||
| 473 | # | ||||||||||||||||||||||||||||||||||||||||||
| 474 | # We turn off DBD::Oracle LOB binds for these partial LOB comparisons by passing | ||||||||||||||||||||||||||||||||||||||||||
| 475 | # dbd_attrs => undef, because these are regular varchar2 comparisons and | ||||||||||||||||||||||||||||||||||||||||||
| 476 | # otherwise the query will fail. | ||||||||||||||||||||||||||||||||||||||||||
| 477 | # | ||||||||||||||||||||||||||||||||||||||||||
| 478 | # Since the most common comparison size is likely to be under 4000 characters | ||||||||||||||||||||||||||||||||||||||||||
| 479 | # (TEXT comparisons previously deployed to other RDBMSes) we disable | ||||||||||||||||||||||||||||||||||||||||||
| 480 | # prepare_cached for queries with more than two part comparisons to a LOB | ||||||||||||||||||||||||||||||||||||||||||
| 481 | # column. This is done in _dbh_execute (above) which was previously overridden | ||||||||||||||||||||||||||||||||||||||||||
| 482 | # to gracefully recover from an Oracle error. This is to be careful to not | ||||||||||||||||||||||||||||||||||||||||||
| 483 | # exhaust your application's open cursor limit. | ||||||||||||||||||||||||||||||||||||||||||
| 484 | # | ||||||||||||||||||||||||||||||||||||||||||
| 485 | # See: | ||||||||||||||||||||||||||||||||||||||||||
| 486 | # http://itcareershift.com/blog1/2011/02/21/oracle-max-number-of-open-cursors-complete-reference-for-the-new-oracle-dba/ | ||||||||||||||||||||||||||||||||||||||||||
| 487 | # on the open_cursor limit. | ||||||||||||||||||||||||||||||||||||||||||
| 488 | # | ||||||||||||||||||||||||||||||||||||||||||
| 489 | # For everything else: | ||||||||||||||||||||||||||||||||||||||||||
| 490 | # | ||||||||||||||||||||||||||||||||||||||||||
| 491 | # We assume that everything that is not a LOB comparison, will most likely be a | ||||||||||||||||||||||||||||||||||||||||||
| 492 | # LIKE query or some sort of function invocation. This may prove to be a naive | ||||||||||||||||||||||||||||||||||||||||||
| 493 | # assumption in the future, but for now it should cover the two most likely | ||||||||||||||||||||||||||||||||||||||||||
| 494 | # things users would want to do with a BLOB or CLOB, an equality test or a LIKE | ||||||||||||||||||||||||||||||||||||||||||
| 495 | # query (on a CLOB.) | ||||||||||||||||||||||||||||||||||||||||||
| 496 | # | ||||||||||||||||||||||||||||||||||||||||||
| 497 | # For these expressions, the bind must NOT have the attributes of a LOB bind for | ||||||||||||||||||||||||||||||||||||||||||
| 498 | # DBD::Oracle, otherwise the query will fail. This is done by passing | ||||||||||||||||||||||||||||||||||||||||||
| 499 | # dbd_attrs => undef. | ||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | sub _prep_for_execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prep_for_execute: not called CC=20 SCAR=60.4
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | my ($op) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | return $self->next::method(@_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 506 | if $op eq 'insert'; | ||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | my ($sql, $bind) = $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | my $lob_bind_indices = { map { | ||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ( | |||||||||||||||||||||||||||||||||||||||||
| 512 | $bind->[$_][0]{sqlt_datatype} | ||||||||||||||||||||||||||||||||||||||||||
| 513 | and | ||||||||||||||||||||||||||||||||||||||||||
| 514 | $self->_is_lob_type($bind->[$_][0]{sqlt_datatype}) | ||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | ) ? ( $_ => 1 ) : () | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$bind->[$_][0]{"sqlt_datatype"} and $self->_is_lob_type($bind->[$_][0]{"sqlt_datatype"})
MC/DC0%0/2
$bind->[$_][0]{"sqlt_datatype"} and $self->_is_lob_type($bind->[$_][0]{"sqlt_datatype"})
$bind->[$_][0]{"sqlt_datatype"}
$self->_is_lob_type($bind->[$_][0]{"sqlt_datatype"})
Truth table0%0/3
A and B
A= $bind->[$_][0]{"sqlt_datatype"}B= $self->_is_lob_type($bind->[$_][0]{"sqlt_datatype"})
| |||||||||||||||||||||||||||||||||||||||||||
| 516 | } ( 0 .. $#$bind ) }; | ||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | ▶ | return ($sql, $bind) unless %$lob_bind_indices; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | my ($final_sql, @final_binds); | |||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | ▶ | if ($op eq 'update') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | $self->throw_exception('Update with complex WHERE clauses involving BLOB columns currently not supported') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | if $sql =~ /\bWHERE\b .+ \bWHERE\b/xs; | ||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | my $where_sql; | |||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | ($final_sql, $where_sql) = $sql =~ /^ (.+?) ( \bWHERE\b .+) /xs; | |||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | if (my $set_bind_count = $final_sql =~ y/?//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | delete $lob_bind_indices->{$_} for (0 .. ($set_bind_count - 1)); | |||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | # bail if only the update part contains blobs | ||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | return ($sql, $bind) unless %$lob_bind_indices; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | @final_binds = splice @$bind, 0, $set_bind_count; | |||||||||||||||||||||||||||||||||||||||||
| 536 | $lob_bind_indices = { map | ||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | { $_ - $set_bind_count => $lob_bind_indices->{$_} } | |||||||||||||||||||||||||||||||||||||||||
| 538 | keys %$lob_bind_indices | ||||||||||||||||||||||||||||||||||||||||||
| 539 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | # if we got that far - assume the where SQL is all we got | ||||||||||||||||||||||||||||||||||||||||||
| 543 | # (the first part is already shoved into $final_sql) | ||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | $sql = $where_sql; | |||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||
| 546 | ▶ | elsif ($op ne 'select' and $op ne 'delete') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$op ne "select" and $op ne "delete"
MC/DC0%0/2
$op ne "select" and $op ne "delete"
$op ne "select"
$op ne "delete"
Truth table0%0/3
A and B
A= $op ne "select"B= $op ne "delete"
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | $self->throw_exception("Unsupported \$op: $op"); | |||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | my @sql_parts = split /\?/, $sql; | |||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | my $col_equality_re = qr/ (?<=\s) ([\w."]+) (\s*=\s*) $/x; | |||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | for my $b_idx (0 .. $#$bind) { | |||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | my $bound = $bind->[$b_idx]; | |||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$lob_bind_indices->{$b_idx} and () = $sql_parts[0] =~ /$col_equality_re/
MC/DC0%0/2
$lob_bind_indices->{$b_idx} and () = $sql_parts[0] =~ /$col_equality_re/
$lob_bind_indices->{$b_idx}
() = $sql_parts[0] =~ /$col_equality_re/
Truth table0%0/3
A and B
A= $lob_bind_indices->{$b_idx}B= () = $sql_parts[0] =~ /$col_equality_re/
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | $lob_bind_indices->{$b_idx} | ||||||||||||||||||||||||||||||||||||||||||
| 559 | and | ||||||||||||||||||||||||||||||||||||||||||
| 560 | my ($col, $eq) = $sql_parts[0] =~ $col_equality_re | ||||||||||||||||||||||||||||||||||||||||||
| 561 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | my $data = $bound->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | ▶ | $data = "$data" if ref $data; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | my @parts = unpack '(a2000)*', $data; | |||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | my @sql_frag; | |||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | for my $idx (0..$#parts) { | |||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | push @sql_frag, sprintf ( | |||||||||||||||||||||||||||||||||||||||||
| 572 | 'UTL_RAW.CAST_TO_VARCHAR2(RAWTOHEX(DBMS_LOB.SUBSTR(%s, 2000, %d))) = ?', | ||||||||||||||||||||||||||||||||||||||||||
| 573 | $col, ($idx*2000 + 1), | ||||||||||||||||||||||||||||||||||||||||||
| 574 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | my $sql_frag = '( ' . (join ' AND ', @sql_frag) . ' )'; | |||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | $sql_parts[0] =~ s/$col_equality_re/$sql_frag/; | |||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | $final_sql .= shift @sql_parts; | |||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | for my $idx (0..$#parts) { | |||||||||||||||||||||||||||||||||||||||||
| 584 | push @final_binds, [ | ||||||||||||||||||||||||||||||||||||||||||
| 585 | { | ||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | %{ $bound->[0] }, | |||||||||||||||||||||||||||||||||||||||||
| 587 | _ora_lob_autosplit_part => $idx, | ||||||||||||||||||||||||||||||||||||||||||
| 588 | dbd_attrs => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 589 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 590 | $parts[$idx] | ||||||||||||||||||||||||||||||||||||||||||
| 591 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||
| 594 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | $final_sql .= shift(@sql_parts) . '?'; | |||||||||||||||||||||||||||||||||||||||||
| 596 | push @final_binds, $lob_bind_indices->{$b_idx} | ||||||||||||||||||||||||||||||||||||||||||
| 597 | ? [ | ||||||||||||||||||||||||||||||||||||||||||
| 598 | { | ||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | ▶ | %{ $bound->[0] }, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 600 | dbd_attrs => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 601 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 602 | $bound->[1], | ||||||||||||||||||||||||||||||||||||||||||
| 603 | ] : $bound | ||||||||||||||||||||||||||||||||||||||||||
| 604 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | ▶ | if (@sql_parts > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | carp "There are more placeholders than binds, this should not happen!"; | |||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | @sql_parts = join ('?', @sql_parts); | |||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | $final_sql .= $sql_parts[0]; | |||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | return ($final_sql, \@final_binds); | |||||||||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||
| 618 | # Savepoints stuff. | ||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | ▶ | sub _exec_svp_begin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exec_svp_begin: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | $self->_dbh->do("SAVEPOINT $name"); | |||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||
| 625 | # Oracle automatically releases a savepoint when you start another one with the | ||||||||||||||||||||||||||||||||||||||||||
| 626 | # same name. | ||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | ▶ | sub _exec_svp_release { 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exec_svp_release: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | ▶ | sub _exec_svp_rollback { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exec_svp_rollback: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | $self->_dbh->do("ROLLBACK TO SAVEPOINT $name") | |||||||||||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||
| 634 | =head2 relname_to_table_alias | ||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||
| 636 | L<DBIx::Class> uses L<DBIx::Class::Relationship> names as table aliases in | ||||||||||||||||||||||||||||||||||||||||||
| 637 | queries. | ||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||
| 639 | Unfortunately, Oracle doesn't support identifiers over 30 chars in length, so | ||||||||||||||||||||||||||||||||||||||||||
| 640 | the L<DBIx::Class::Relationship> name is shortened and appended with half of an | ||||||||||||||||||||||||||||||||||||||||||
| 641 | MD5 hash. | ||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||
| 643 | See L<DBIx::Class::Storage::DBI/relname_to_table_alias>. | ||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||
| 645 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | ▶ | sub relname_to_table_alias { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
relname_to_table_alias: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | my ($relname, $join_count) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | my $alias = $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||
| 653 | # we need to shorten here in addition to the shortening in SQLMaker itself, | ||||||||||||||||||||||||||||||||||||||||||
| 654 | # since the final relnames are crucial for the join optimizer | ||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | return $self->sql_maker->_shorten_identifier($alias); | |||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||
| 658 | =head2 with_deferred_fk_checks | ||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||
| 660 | Runs a coderef between: | ||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||
| 662 | alter session set constraints = deferred | ||||||||||||||||||||||||||||||||||||||||||
| 663 | ... | ||||||||||||||||||||||||||||||||||||||||||
| 664 | alter session set constraints = immediate | ||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||
| 666 | to defer foreign key checks. | ||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | Constraints must be declared C<DEFERRABLE> for this to work. | ||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||
| 670 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | ▶ | sub with_deferred_fk_checks { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
with_deferred_fk_checks: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | my ($self, $sub) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | my $txn_scope_guard = $self->txn_scope_guard; | |||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | $self->_do_query('alter session set constraints = deferred'); | |||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | ▶ | my $sg = Scope::Guard->new(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | $self->_do_query('alter session set constraints = immediate'); | |||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||
| 683 | return | ||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | ▶ | preserve_context { $sub->() } after => sub { $txn_scope_guard->commit }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||
| 687 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||
| 689 | Following additional attributes can be used in resultsets. | ||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||
| 691 | =head2 connect_by or connect_by_nocycle | ||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||
| 693 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||
| 695 | =item Value: \%connect_by | ||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||
| 697 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||
| 699 | A hashref of conditions used to specify the relationship between parent rows | ||||||||||||||||||||||||||||||||||||||||||
| 700 | and child rows of the hierarchy. | ||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||
| 703 | connect_by => { parentid => 'prior personid' } | ||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||
| 705 | # adds a connect by statement to the query: | ||||||||||||||||||||||||||||||||||||||||||
| 706 | # SELECT | ||||||||||||||||||||||||||||||||||||||||||
| 707 | # me.persionid me.firstname, me.lastname, me.parentid | ||||||||||||||||||||||||||||||||||||||||||
| 708 | # FROM | ||||||||||||||||||||||||||||||||||||||||||
| 709 | # person me | ||||||||||||||||||||||||||||||||||||||||||
| 710 | # CONNECT BY | ||||||||||||||||||||||||||||||||||||||||||
| 711 | # parentid = prior persionid | ||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||
| 714 | connect_by_nocycle => { parentid => 'prior personid' } | ||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||
| 716 | # adds a connect by statement to the query: | ||||||||||||||||||||||||||||||||||||||||||
| 717 | # SELECT | ||||||||||||||||||||||||||||||||||||||||||
| 718 | # me.persionid me.firstname, me.lastname, me.parentid | ||||||||||||||||||||||||||||||||||||||||||
| 719 | # FROM | ||||||||||||||||||||||||||||||||||||||||||
| 720 | # person me | ||||||||||||||||||||||||||||||||||||||||||
| 721 | # CONNECT BY NOCYCLE | ||||||||||||||||||||||||||||||||||||||||||
| 722 | # parentid = prior persionid | ||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||
| 725 | =head2 start_with | ||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||
| 729 | =item Value: \%condition | ||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||
| 731 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||
| 733 | A hashref of conditions which specify the root row(s) of the hierarchy. | ||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||
| 735 | It uses the same syntax as L<DBIx::Class::ResultSet/search> | ||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||
| 737 | start_with => { firstname => 'Foo', lastname => 'Bar' } | ||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||
| 739 | # SELECT | ||||||||||||||||||||||||||||||||||||||||||
| 740 | # me.persionid me.firstname, me.lastname, me.parentid | ||||||||||||||||||||||||||||||||||||||||||
| 741 | # FROM | ||||||||||||||||||||||||||||||||||||||||||
| 742 | # person me | ||||||||||||||||||||||||||||||||||||||||||
| 743 | # START WITH | ||||||||||||||||||||||||||||||||||||||||||
| 744 | # firstname = 'foo' and lastname = 'bar' | ||||||||||||||||||||||||||||||||||||||||||
| 745 | # CONNECT BY | ||||||||||||||||||||||||||||||||||||||||||
| 746 | # parentid = prior persionid | ||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||
| 748 | =head2 order_siblings_by | ||||||||||||||||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||||||||||||||||
| 750 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||
| 752 | =item Value: ($order_siblings_by | \@order_siblings_by) | ||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||
| 754 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||
| 756 | Which column(s) to order the siblings by. | ||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||
| 758 | It uses the same syntax as L<DBIx::Class::ResultSet/order_by> | ||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||
| 760 | 'order_siblings_by' => 'firstname ASC' | ||||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||
| 762 | # SELECT | ||||||||||||||||||||||||||||||||||||||||||
| 763 | # me.persionid me.firstname, me.lastname, me.parentid | ||||||||||||||||||||||||||||||||||||||||||
| 764 | # FROM | ||||||||||||||||||||||||||||||||||||||||||
| 765 | # person me | ||||||||||||||||||||||||||||||||||||||||||
| 766 | # CONNECT BY | ||||||||||||||||||||||||||||||||||||||||||
| 767 | # parentid = prior persionid | ||||||||||||||||||||||||||||||||||||||||||
| 768 | # ORDER SIBLINGS BY | ||||||||||||||||||||||||||||||||||||||||||
| 769 | # firstname ASC | ||||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||||
| 771 | =head1 FURTHER QUESTIONS? | ||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||
| 773 | Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>. | ||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||
| 775 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||
| 777 | This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE> | ||||||||||||||||||||||||||||||||||||||||||
| 778 | by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can | ||||||||||||||||||||||||||||||||||||||||||
| 779 | redistribute it and/or modify it under the same terms as the | ||||||||||||||||||||||||||||||||||||||||||
| 780 | L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>. | ||||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||
| 782 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||
| 784 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 785 | # vim:sts=2 sw=2: | ||||||||||||||||||||||||||||||||||||||||||