Oracle/Storage.pm

filter: Statementstmt 79.4% 120 / 151 Branchbran 71.2% 47 / 66 Conditioncond 58.8% 30 / 51 MC/DCmcdc 44.8% 13 / 29 Subroutinesub 72.9% 27 / 37 Podpod 80.0% 4 / 5 totaltotal 71.0% 241 / 339 CC 53 SCAR 20.5
CC
53
Cov
74%
_mask_error_values
20.0
_dbh_execute
20.0
__ANON__
20.0
CRAP 7.8
« Oracle/Diff/Table.pm ↑ Summary Oracle/SQLMaker.pm »
1 package DBIO::Oracle::Storage;
2 # ABSTRACT: Oracle Support for DBIO
3  
4 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 23 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 23 our $VERSION = '0.900007';
8  
9 # Compose cross-cutting Storage behaviour via ISA (not Exporter import), so the
10 # role methods live in the MRO and their next::method calls resolve. Roles that
11 # override a DBIO::Storage::DBI method (LOBSupport::_prep_for_execute,
12 # Savepoints::_dbh_execute_for_fetch) come BEFORE DBIO::Storage::DBI so the
13 # override wins and chains forward to the base.
14 23 ▶use base qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
15 DBIO::Oracle::Storage::LOBSupport
16 DBIO::Oracle::Storage::AutoIncrement
17 DBIO::Oracle::Storage::Savepoints
18 DBIO::Oracle::Storage::FKDeferral
19 DBIO::Oracle::Storage::ConnectSetup
20 DBIO::Storage::DBI
21 23 /;
22 23 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 23 __PACKAGE__->register_driver('Oracle' => __PACKAGE__);
25  
26 23 ▶use DBIO::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 23 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 23 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 23 __PACKAGE__->sql_quote_char ('"');
31 23 __PACKAGE__->sql_maker_class('DBIO::Oracle::SQLMaker');
32 23 __PACKAGE__->datetime_parser_type('DateTime::Format::Oracle');
33  
34 23 ▶use DBIO::Oracle::Type ();
Subroutine BEGIN: called CC=1 SCAR=0.0
35 23 ▶use DBIO::Oracle::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 0 ▶sub __cache_queries_with_max_lob_parts { 2 }
Subroutine __cache_queries_with_max_lob_parts: not called CC=1 SCAR=6.9
38  
39 1 ▶sub dbio_deploy_class { 'DBIO::Oracle::Deploy' }
Subroutine dbio_deploy_class: called CC=1 SCAR=0.0
Pod undocumented
40  
41 # a DATE holds a date and a time of day
42 3 ▶sub datetime_date_carries_time { 1 }
Subroutine datetime_date_carries_time: called CC=1 SCAR=0.0
Pod documented
43  
44 # The attributes of every connection of this driver that the connect_info does
45 # not name (an attribute it names wins, core merges it over these): LongReadLen
46 # 16 MiB, so a CLOB or BLOB is read in full instead of dying at DBD::Oracle's
47 # 80 characters (LongTruncOk stays off: a cut value is an error, never a silent
48 # one), and AL32UTF8 as the client character sets, so a character is not turned
49 # into U+FFFD by a client NLS_LANG that is not UTF-8 (karr k63).
50 61 ▶sub _default_dbi_connect_attributes () {
Subroutine _default_dbi_connect_attributes: called CC=1 SCAR=0.0
51 +{
52 61 %{ $_[0]->next::method },
53 LongReadLen => 16 * 1024 * 1024,
54 ora_charset => 'AL32UTF8',
55 ora_ncharset => 'AL32UTF8',
56 };
57 }
58 0 ▶sub deploy_setup { }
Subroutine deploy_setup: not called CC=1 SCAR=0.0
Pod documented
59  
60  
61 0 ▶sub _determine_supports_insert_returning {
Subroutine _determine_supports_insert_returning: not called CC=2 SCAR=17.9
62 0 my $self = shift;
63 # TODO find out which version supports the RETURNING syntax
64 # 8i has it and earlier docs are a 404 on oracle.com
65 0 ▶ return 1 if $self->_server_info->{normalized_dbms_version} >= 8.001;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_server_info->{"normalized_dbms_version"} >= "8.001" 0 0 0
66 0 return 0;
67 }
68  
69 23 __PACKAGE__->_use_insert_returning_bound (1);
70  
71 # F02 / F10 -- transactional DDL. Zero, and here that is the ENGINE's answer
72 # rather than this driver's preference: on Oracle a DDL statement is not
73 # something a transaction can contain. The SQL Language Reference states it as
74 # a property of COMMIT itself -- "Oracle Database issues an implicit COMMIT
75 # under the following circumstances: * Before any syntactically valid data
76 # definition language (DDL) statement, even if the statement results in an
77 # error * After any data definition language (DDL) statement that completes
78 # without an error" (19c SQL Language Reference, COMMIT) -- and the 2 Day
79 # Developer's Guide draws the conclusion in one sentence: "Before and after a
80 # DDL statement, Oracle Database issues an implicit COMMIT statement;
81 # therefore, you cannot roll back a DDL statement" (19c 2 Day Developer's
82 # Guide, About Data Definition Language (DDL) Statements).
83 #
84 # The load-bearing clause is "even if the statement results in an error": the
85 # COMMIT in FRONT of a DDL statement is not conditional on that statement
86 # working. So a $storage->txn_do around DBIO::Deploy::Base::_execute_ddl's
87 # loop would not merely fail to buy atomicity here -- it would be actively
88 # misleading. txn_do opens a transaction; the first CREATE TABLE commits it,
89 # together with whatever the caller had already done inside it; every further
90 # statement commits on both sides of itself; and the ROLLBACK txn_do issues
91 # when statement 7 of 12 throws has nothing left to reach. The bracket would
92 # read as atomicity at the call site and hand back a committed, half-migrated
93 # schema -- which is strictly worse than core's honest one-time
94 # "non-transactional DDL" notice.
95 #
96 # The very same paragraph of COMMIT is also why this driver's own deploy
97 # cannot be produced as the counter-example: "This statement also erases all
98 # savepoints in the transaction and releases transaction locks."
99 # DBIO::Oracle::Deploy was written to run its test deploy inside a SAVEPOINT
100 # on the live connection (ADR 0002), and that savepoint does not survive the
101 # first CREATE TABLE of the deploy it is meant to contain -- which is why its
102 # diff and upgrade build the desired state in a temporary user instead (karr
103 # k36, ADR 0010). See DBIO::Oracle::Deploy, "The desired state: a temporary
104 # user", for that, and "Transactional DDL" for what is left to recover with
105 # after a half-run apply.
106 #
107 # No version gate, and none is possible: the implicit COMMIT on DDL is
108 # Oracle's behaviour on every release this driver supports, so there is
109 # nothing for a _determine_supports_transactional_ddl to probe. Declared
110 # outright rather than left to core's default -- which is also 0 -- because a
111 # silent storage cannot be told apart from an overlooked one, and the default
112 # is core's to change.
113 #
114 # MEASURED IN PART. That a DDL statement commits the transaction it finds
115 # open -- also one that fails on the name -- and that a savepoint is gone
116 # after it, is measured against Oracle Database 23ai Free (23.26.3) in
117 # t/54-deploy-live.t (1d, 4). NOT measured: a txn_do bracket around the
118 # deploy loop on a server, and any other release. For those the above is
119 # documented engine behaviour with its sources named, in the same sense as
120 # the EXPLAIN PLAN and DBMS_RANDOM work above. Value and
121 # declaredness, plus the bracket/no-bracket behaviour it drives in core, are
122 # pinned offline by t/52-deploy-transactional-ddl.t.
123 23 __PACKAGE__->_use_transactional_ddl (0);
124  
125 # ADR 0039 -- does this deployment's Oracle have the "... ALL" set operators?
126 # Declared 0 outright, which is what keeps the hook below a *static class
127 # fact*: an undeclared capability falls through to _determine_supports_*, and
128 # the only honest determination here would read the server version. See the
129 # refusal in _set_operation_keyword for why that is forbidden rather than
130 # merely inconvenient -- and note that this is the spot where a future author
131 # would be tempted to add the probe, so it is nailed shut on both tiers.
132 23 __PACKAGE__->mk_group_accessors( dbms_capability => '_supports_set_operator_all_family' );
133 23 __PACKAGE__->mk_group_accessors( use_dbms_capability => '_use_set_operator_all_family' );
134 23 __PACKAGE__->_use_set_operator_all_family (0);
135 0 ▶sub _determine_supports_set_operator_all_family { 0 }
Subroutine _determine_supports_set_operator_all_family: not called CC=1 SCAR=6.9
136  
137 # ADR 0039 -- the keyword the six DBIO::ResultSet set operations join their
138 # operands with, and the seam that refuses the two Oracle did not have until
139 # 21c. Replaces ADR 0037's single-operation _except_operator, which core
140 # removed; an unported override would simply never have been called again.
141 #
142 # Deliberately a static class fact with no version probe: ResultSet's
143 # _set_operation bakes the keyword into a literal from clause at construction
144 # time, so a runtime-resolved keyword is not expressible -- and asking the
145 # server which word to use is exactly the connection-at-query-build-time this
146 # hook removed.
147 17 ▶sub _set_operation_keyword {
Subroutine _set_operation_keyword: called CC=7 SCAR=19.5
148 17 my ($self, $op) = @_;
149  
150 # An undefined $op is a core programming error and the base throws for it;
151 # it only ever sees one if this override passes it down, and the comparisons
152 # below would warn about an uninitialized value first.
153 17 ▶ return $self->next::method($op) unless defined $op;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $op 1 16 17
154  
155 # MINUS on every release since 8i and still one in 23ai. EXCEPT was only
156 # added alongside it in 21c and is a syntax error on everything older, so
157 # this answer carries no version gate and needs none.
158 16 ▶ return 'MINUS' if $op eq 'except';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "except" 2 14 16
159  
160 # Before 21c the engine has exactly UNION, UNION ALL, INTERSECT and MINUS
161 # (SQL Language Reference, "The Set Operators", 19c); 21c added EXCEPT,
162 # EXCEPT ALL, INTERSECT ALL and MINUS ALL. Which of the two we are talking
163 # to is not askable here, so the class fact decides it.
164 14 ▶ if ($op eq 'except_all' or $op eq 'intersect_all') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "except_all" or $op eq "intersect_all") 10 4 14
Condition100%3/3
$op eq "except_all" or $op eq "intersect_all"
l!l&&r!l&&!r
824
MC/DC100%2/2
$op eq "except_all" or $op eq "intersect_all"
$op eq "except_all" $op eq "intersect_all"
Truth table100%3/3
A or B
A= $op eq "except_all"B= $op eq "intersect_all"
ABresult
1X1
011
000
165  
166 10 ▶ $self->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_use_set_operator_all_family 6 4 10
167 "Oracle has no MINUS ALL / INTERSECT ALL before 21c, so this driver "
168 . "refuses \$rs->$op. The refusal holds by default on every version, 21c "
169 . "and later included, because _set_operation_keyword must answer as a "
170 . "static class fact: DBIO::ResultSet::_set_operation bakes the keyword "
171 . "into the query while it is being built, so probing the server version "
172 . "here would open a connection during query build -- purely in order to "
173 . "throw (ADR 0039 section 7). A deployment that knows it runs 21c or "
174 . "newer lifts the refusal with "
175 . "DBIO::Oracle::Storage->_use_set_operator_all_family(1), or for a "
176 . "single connection with "
177 . "\$schema->storage->_use_set_operator_all_family(1)."
178 ) unless $self->_use_set_operator_all_family;
179  
180 # 21c spells this one both ways. MINUS ALL rather than the equally valid
181 # EXCEPT ALL so that except and except_all come out of the same dialect.
182 4 ▶ return 'MINUS ALL' if $op eq 'except_all';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "except_all" 3 1 4
183 }
184  
185 # UNION, UNION ALL, INTERSECT -- and INTERSECT ALL once opted in: Oracle's
186 # spelling is the ANSI one, so the base map answers. An unknown $op lands on
187 # core's throw there rather than being invented here.
188 5 return $self->next::method($op);
189 }
190  
191 # ADR 0037 -- the complete 1/0 statement behind DBIO::ResultSet::results_exist
192 # and its two siblings. Core's base rendering has no FROM clause at all, and
193 # Oracle answers a FROM-less SELECT with ORA-00923; DUAL is the one-row table
194 # that makes it a legal statement here. Only the dummy table is ours -- the
195 # CASE spelling stays core's, so there is one copy of it.
196 3 ▶sub _exists_value_sql {
Subroutine _exists_value_sql: called CC=1 SCAR=0.0
197 3 my $self = shift;
198 3 return $self->next::method(@_) . ' FROM DUAL';
199 }
200  
201 # ... and the capability that lets core call the above at all. Not vacuous
202 # next to the override: it is this driver asserting that somebody checked the
203 # rendering against Oracle, which is why the default is 0 and why declaring is
204 # a separate act from overriding.
205 23 __PACKAGE__->_use_supports_exists_query (1);
206  
207 # karr k22 -- the function DBIO::ResultSet::rand drops into an order_by
208 # literal. Core answers RANDOM(), which PostgreSQL and SQLite have and Oracle
209 # does not have at all: the server reports it as an unknown identifier
210 # (ORA-00904), because there is no such function to resolve the name to.
211 #
212 # DBMS_RANDOM.VALUE is the supplied-package function, written WITHOUT
213 # parentheses: this is its zero-argument overload, and SQL has no empty
214 # argument list to write for it. A static class fact like the base hook -- no
215 # $dbh, no version probe.
216 3 ▶sub _random_function { 'DBMS_RANDOM.VALUE' }
Subroutine _random_function: called CC=1 SCAR=0.0
217  
218 # karr k22 / ADR 0040 -- the WHOLE operation of obtaining a query plan, which
219 # on Oracle is two statements and was the reason core widened this seam from
220 # the string-valued _explain_sql to a method returning rows.
221 #
222 # Core's inherited operation is "EXPLAIN <query>", and Oracle has no EXPLAIN
223 # statement -- it has EXPLAIN PLAN, and the bare form is a syntax error
224 # (ORA-00900). The spelling is the smaller half: EXPLAIN PLAN FOR does not
225 # ANSWER with the plan. It writes it into PLAN_TABLE and returns no rows at
226 # all, so the plan has to be read back by a second statement of this driver's
227 # own, which core never rendered and knows nothing about.
228 #
229 # DBMS_XPLAN.DISPLAY with no arguments reads the most recently explained
230 # statement out of PLAN_TABLE, which is the one the line above just wrote.
231 # PLAN_TABLE is session-private (a global temporary table since 10g), so the
232 # two statements must run on the same connection -- they do, because core
233 # delegates this whole method rather than the statements inside it, so a
234 # DBIO::Replicated::Storage picks one replicant for the operation and both land
235 # on it (DBIO::Replicated::Balancer::_explain_query).
236 #
237 # BOTH statements go through _execute_rendered, which ADR 0040 section 3 makes
238 # a requirement of the contract with no engine-named exceptions -- including
239 # the second one, which carries no user data but everything else: tracing and
240 # therefore redact_bind_value (ADR 0025) over the query's own WHERE-clause
241 # values, dbh_do retry over a dropped connection, NoBindVars interpolation, and
242 # the read handler rather than the master's on a replicated storage. Reaching
243 # for $self->dbh here would hand every one of them back, and this driver's
244 # EXPLAIN PLAN FOR would be the loudest place to lose them: the binds it
245 # carries are the caller's own.
246 1 ▶sub _explain_query {
Subroutine _explain_query: called CC=1 SCAR=0.0
247 1 my ($self, $sql, $bind) = @_;
248  
249 # Writes the plan into PLAN_TABLE and answers nothing. The query's binds
250 # travel with it: EXPLAIN PLAN parses the statement, so its placeholders are
251 # the statement's own and have to be supplied.
252 1 $self->_execute_rendered("EXPLAIN PLAN FOR $sql", $bind);
253  
254 # ... so the plan comes from here. One column, PLAN_TABLE_OUTPUT, one row per
255 # line of DBMS_XPLAN's formatted report.
256 1 my (undef, $sth) = $self->_execute_rendered(
257 'SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY)', [],
258 );
259  
260 1 return $sth->fetchall_arrayref;
261 }
262  
263  
264 2 ▶sub insert {
Subroutine insert: called CC=7 SCAR=20.9
Pod documented
265 2 my ($self, $source, $to_insert, $opts) = @_;
266  
267 2 ▶ return $self->next::method($source, $to_insert, $opts)
Branch: 1 branch
BranchTrueFalseTotal
if $to_insert and %$to_insert 1 1 2
Condition66%2/3
$to_insert and %$to_insert
!ll&&!rl&&r
011
MC/DC50%1/2
$to_insert and %$to_insert
$to_insert %$to_insert
Truth table66%2/3
A and B
A= $to_insertB= %$to_insert
ABresult
0X0
100
111
268 if $to_insert and %$to_insert;
269  
270 1 my $infos = $source->columns_info;
271 1 my ($col) = grep { $infos->{$_}{is_auto_increment} } $source->columns;
272 1 ▶ ($col) = $source->columns unless defined $col;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $col 0 1 1
273 1 ▶ return $self->next::method($source, $to_insert, $opts) unless defined $col;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $col 0 1 1
274  
275 1 my $returned = $self->next::method($source, { $col => \'DEFAULT' }, $opts);
276 delete $returned->{$col}
277 0 ▶ if ref $returned->{$col} eq 'SCALAR' and ${ $returned->{$col} } eq 'DEFAULT';
Branch: 1 branch
BranchTrueFalseTotal
if ref $returned->{$col} eq "SCALAR" and ${$returned->{$col};} eq "DEFAULT" 0 1 1
Condition33%1/3
ref $returned->{$col} eq "SCALAR" and ${$returned->{$col};} eq "DEFAULT"
!ll&&!rl&&r
100
MC/DC0%0/2
ref $returned->{$col} eq "SCALAR" and ${$returned->{$col};} eq "DEFAULT"
ref $returned->{$col} eq "SCALAR" ${$returned->{$col};} eq "DEFAULT"
Truth table33%1/3
A and B
A= ref $returned->{$col} eq "SCALAR"B= ${$returned->{$col};} eq "DEFAULT"
ABresult
0X0
100
111
278 1 return $returned;
279 }
280  
281  
282 2 ▶sub _insert_bulk {
Subroutine _insert_bulk: called CC=4 SCAR=13.9
283 2 my ($self, $source, $cols, $data, @rest) = @_;
284  
285 2 my $infos = $source->columns_info($cols);
286 return $self->next::method($source, $cols, $data, @rest)
287 2 ▶ unless grep { defined $infos->{$_}{data_type} and $self->_is_lob_type($infos->{$_}{data_type}) } @$cols;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {defined $infos->{$_}{"data_type"} and $self->_is_lob_type($infos->{$_}{"data_type"});} @$cols 1 1 2
Condition66%2/3
defined $infos->{$_}{'data_type'} && $self->_is_lob_type($infos->{$_}{'data_type'})
!ll&&!rl&&r
021
MC/DC50%1/2
defined $infos->{$_}{'data_type'} && $self->_is_lob_type($infos->{$_}{'data_type'})
defined $infos->{$_}{'data_type'} $self->_is_lob_type($infos->{$_}{'data_type'})
Truth table66%2/3
A && B
A= defined $infos->{$_}{'data_type'}B= $self->_is_lob_type($infos->{$_}{'data_type'})
ABresult
0X0
100
111
288  
289 1 my $guard = $self->txn_scope_guard;
290 1 for my $row (@$data) {
291 2 my %values;
292 2 @values{@$cols} = @$row;
293 2 $self->insert($source, \%values, { no_retrieve => 1 });
294 }
295 1 $guard->commit;
296 1 return scalar @$data;
297 }
298  
299 0 ▶sub _ping {
Subroutine _ping: not called CC=2 SCAR=17.9
300 0 my $self = shift;
301 0 ▶ my $dbh = $self->_dbh or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = $self->_dbh or return 0 0 0 0
302 0 local $dbh->{RaiseError} = 1;
303 0 local $dbh->{PrintError} = 0;
304 0 ▶ return try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
305 0 $dbh->do('select 1 from dual');
306 0 1;
307 0 ▶ } catch { 0 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
308 }
309  
310 # A Perl string without the UTF-8 flag is a sequence of Latin-1 code points,
311 # but DBD::Oracle sends it as bytes: under the client character set AL32UTF8 a
312 # "\x{fc}" arrives as the invalid byte 0xFC and comes back as U+FFFD (karr k63,
313 # case bind-non-ascii). The bind is upgraded (utf8::upgrade, on a copy: the
314 # caller's string is not touched) when its data type is a character type; a
315 # binary type and a bind without a type are sent as they are.
316 26 ▶sub _is_character_data_type {
Subroutine _is_character_data_type: called CC=3 SCAR=11.0
317 26 my ($self, $data_type) = @_;
318  
319 26 ▶ return 0 unless defined $data_type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_type 1 25 26
320  
321 25 ▶ return $data_type =~ /\A \s*
Branch: 1 branch
BranchTrueFalseTotal
$data_type =~ /\A \s* (?: (?: national \s+ )? (?: char (?: acter )? (?: \s+ varying )? | varchar2? | nvarchar2? | nchar (?: \s+ varying )? ) | text | tinytext | mediumtext | longtext | n?clob | long | string ) \s* (?: \( [^)]* \) )? \s* \z/xi ? : 16 9 25
322 (?: (?: national \s+ )?
323 (?: char (?: acter )? (?: \s+ varying )? | varchar2? | nvarchar2? | nchar (?: \s+ varying )? )
324 | text | tinytext | mediumtext | longtext | n?clob | long | string )
325 \s* (?: \( [^)]* \) )? \s* \z/xi ? 1 : 0;
326 }
327  
328 28 ▶sub _upgrade_character_bind {
Subroutine _upgrade_character_bind: called CC=5 SCAR=16.1
329 28 my ($self, $meta, $value) = @_;
330  
331 return $value
332 unless defined $value
333 and !length ref $value
334 and ref $meta eq 'HASH'
335 28 ▶ and $self->_is_character_data_type($meta->{sqlt_datatype});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not length ref $value and ref $meta eq "HASH" and $self->_is_character_data_type($meta->{"sqlt_datatype"}) 12 16 28
Condition88%8/9
defined $value and not length ref $value and ref $meta eq "HASH" and $self->_is_character_data_type($meta->{"sqlt_datatype"})
!ll&&!rl&&r
21016
defined $value and not length ref $value and ref $meta eq "HASH"
!ll&&!rl&&r
2026
defined $value and not length ref $value
!ll&&!rl&&r
1126
MC/DC75%3/4
defined $value and not length ref $value and ref $meta eq "HASH" and $self->_is_character_data_type($meta->{"sqlt_datatype"})
defined $value not length ref $value ref $meta eq "HASH" $self->_is_character_data_type($meta->{"sqlt_datatype"})
Truth table80%4/5
A and not(B) and C and D
A= defined $valueB= not length ref $valueC= ref $meta eq "HASH"D= $self->_is_character_data_type($meta->{"sqlt_datatype"})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
336  
337 16 utf8::upgrade(my $copy = $value);
338 16 return $copy;
339 }
340  
341 # The one core seam for a changed value (DBIO::Storage::DBI, _adjust_bind_values):
342 # statements bound one by one and each row of a void populate run through it.
343 # The answer is a new list of new pairs; a scalar reference (a bind_param_inout
344 # target) stays the very same reference, and the caller's list and strings are
345 # never written to. In a populate row the meta of a literal-bind slot carries
346 # _literal_bind_subindex; that value is left as it is.
347 27 ▶sub _adjust_bind_values {
Subroutine _adjust_bind_values: called CC=3 SCAR=12.0
348 27 my ($self, $sth, $bind, $bind_attrs) = @_;
349  
350 return [ map {
351 ( ref $_->[0] eq 'HASH' and defined $_->[0]{_literal_bind_subindex} )
352 28 ▶ ? [ @$_ ]
Branch: 1 branch
BranchTrueFalseTotal
ref $_->[0] eq 'HASH' && defined $_->[0]{'_literal_bind_subindex'} ? : 0 28 28
Condition33%1/3
ref $_->[0] eq "HASH" and defined $_->[0]{"_literal_bind_subindex"}
!ll&&!rl&&r
0280
MC/DC0%0/2
ref $_->[0] eq "HASH" and defined $_->[0]{"_literal_bind_subindex"}
ref $_->[0] eq "HASH" defined $_->[0]{"_literal_bind_subindex"}
Truth table33%1/3
A and B
A= ref $_->[0] eq "HASH"B= defined $_->[0]{"_literal_bind_subindex"}
ABresult
0X0
100
111
353 : [ $_->[0], $self->_upgrade_character_bind(@$_[0, 1]) ]
354 27 } @{ $self->next::method($sth, $bind, $bind_attrs) } ];
355 }
356  
357  
358 35 ▶sub _ddl_sql_dialect { 'oracle' }
Subroutine _ddl_sql_dialect: called CC=1 SCAR=0.0
359  
360  
361 0 ▶sub _mask_error_values {
Subroutine _mask_error_values: not called CC=4 SCAR=30.0
362 0 my ($self, $text, $values, $statement) = @_;
363  
364 0 ▶ return $text unless defined $text and !ref $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and not ref $text 0 0 0
Condition0%0/3
defined $text and not ref $text
!ll&&!rl&&r
000
MC/DC0%0/2
defined $text and not ref $text
defined $text not ref $text
Truth table0%0/3
A and not(B)
A= defined $textB= not ref $text
ABresult
0X0
100
111
365  
366 0 my $masked = eval { DBIO::Oracle::Util::mask_error_details($text, $values, $statement) };
367 0 ▶ $masked = $text unless defined $masked;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $masked 0 0 0
368  
369 0 return $self->next::method($masked, $values, $statement);
370 }
371  
372 0 ▶sub _dbh_execute {
Subroutine _dbh_execute: not called CC=4 SCAR=30.0
373 0 my ($self, $sql, $bind) = @_[0,2,3];
374  
375 # Turn off sth caching for multi-part LOBs. See _prep_for_execute below
376 local $self->{disable_sth_caching} = 1 if grep {
377 0 ▶ ($_->[0]{_ora_lob_autosplit_part}||0) > (__cache_queries_with_max_lob_parts - 1)
Branch: 1 branch
BranchTrueFalseTotal
if grep {($_->[0]{"_ora_lob_autosplit_part"} || 0) > __cache_queries_with_max_lob_parts(-1);} @$bind 0 0 0
Condition0%0/2
$_->[0]{'_ora_lob_autosplit_part'} || 0
l!l
00
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'}
Aresult
11
00
378 } @$bind;
379  
380 0 my $next = $self->next::can;
381  
382 # if we are already in a txn we can't retry anything
383 0 ▶ return shift->$next(@_) if $self->transaction_depth;
Branch: 1 branch
BranchTrueFalseTotal
if $self->transaction_depth 0 0 0
384  
385 0 local $self->{_in_do_block};
386  
387 return DBIO::Storage::BlockRunner->new(
388 storage => $self,
389 wrap_txn => 0,
390 0 ▶ retry_handler => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
391 0 ▶ if ($_[0]->failed_attempt_count == 1
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]->failed_attempt_count == 1 and $_[0]->last_exception =~ /ORA-01003/ and my $dbh = $_[0]->storage->_dbh) 0 0 0
Condition0%0/6
$_[0]->failed_attempt_count == 1 and $_[0]->last_exception =~ /ORA-01003/ and my $dbh = $_[0]->storage->_dbh
!ll&&!rl&&r
000
$_[0]->failed_attempt_count == 1 and $_[0]->last_exception =~ /ORA-01003/
!ll&&!rl&&r
000
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
ABCresult
0XX0
10X0
1100
1111
392 and $_[0]->last_exception =~ /ORA-01003/
393 and my $dbh = $_[0]->storage->_dbh) {
394 0 delete $dbh->{CachedKids}{$sql};
395 0 return 1;
396 }
397 0 return 0;
398 },
399 0 )->run($next, @_);
400 }
401  
402  
403 23 ▶sub _connect_params_dsn {
Subroutine _connect_params_dsn: called CC=6 SCAR=17.9
404 23 my ($self, $driver, $params) = @_;
405  
406 23 my ($dbname, $host, $port) = @{$params}{qw(dbname host port)};
407  
408 23 ▶ if (defined $host) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $host) 13 10 23
409 13 ▶ return "dbi:$driver://$host"
Branch: 2 branches
BranchTrueFalseTotal
defined $port ? : 9 4 13
defined $dbname ? : 9 4 13
410 . ( defined $port ? ":$port" : '' )
411 . ( defined $dbname ? "/$dbname" : '' );
412 }
413  
414 $self->throw_exception(
415 10 ▶ 'Cannot build a DBD::Oracle DSN from the connection parameter port '
Branch: 1 branch
BranchTrueFalseTotal
if defined $port 4 6 10
416 . 'without a host: DBD::Oracle connects to a database the Oracle client '
417 . "resolves by name (dbi:$driver:<dbname>) or, with Easy Connect, to a "
418 . "service on a host (dbi:$driver://<host>[:<port>][/<dbname>]), and only "
419 . 'the second has a place for a port. Beside a name the port would be '
420 . 'dropped -- tnsnames.ora or the local instance decides where the '
421 . 'connection goes. Give host as well, leave port out, or supply a dsn '
422 . 'instead.'
423 ) if defined $port;
424  
425 6 ▶ return "dbi:$driver:" . ( $dbname // '' );
Condition100%2/2
$dbname // ""
l!l
33
MC/DC100%1/1
$dbname // ""
$dbname
Truth table100%2/2
A
A= $dbname
Aresult
11
00
426 }
427  
428  
429 40 ▶sub _bind_host_into_dsn {
Subroutine _bind_host_into_dsn: called CC=14 SCAR=26.5
430 40 my ($self, $driver, $dsn, $host, $port) = @_;
431  
432 40 ▶ return $self->next::method($driver, $dsn, $host, $port)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dsn and $dsn =~ /^(dbi:Oracle(?:\([^)]*\))?:)(.*)\z/is 0 40 40
Condition33%1/3
defined $dsn and $dsn =~ /^(dbi:Oracle(?:\([^)]*\))?:)(.*)\z/is
!ll&&!rl&&r
0040
MC/DC0%0/2
defined $dsn and $dsn =~ /^(dbi:Oracle(?:\([^)]*\))?:)(.*)\z/is
defined $dsn $dsn =~ /^(dbi:Oracle(?:\([^)]*\))?:)(.*)\z/is
Truth table33%1/3
A and B
A= defined $dsnB= $dsn =~ /^(dbi:Oracle(?:\([^)]*\))?:)(.*)\z/is
ABresult
0X0
100
111
433 unless defined $dsn and $dsn =~ /^(dbi:Oracle(?:\([^)]*\))?:)(.*)\z/is;
434 40 my ($prefix, $rest) = ($1, $2);
435  
436 40 ▶ if ($rest =~ m{^//(.*)\z}s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ m[^//(.*)\z]s) 28 12 40
437 28 my $tail = $1;
438 28 my ($authority, $service) = $tail =~ m{^([^/]*)(/.*)?\z}s;
439 28 ▶ $service //= '';
Condition100%2/2
$service //= ""
l!l
244
MC/DC100%1/1
$service //= ""
$service
Truth table100%2/2
A
A= $service
Aresult
11
00
440  
441 28 my ($old_host, $old_port);
442 28 ▶ if ($authority =~ /^(\[[^\]]+\]|[^:\[\]]+)(?::(\d*))?\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($authority =~ /^(\[[^\]]+\]|[^:\[\]]+)(?::(\d*))?\z/) { } 24 4 28
443 24 ($old_host, $old_port) = ($1, $2);
444 }
445 else {
446 4 return (undef, 'an Easy Connect DSN whose host part cannot be read');
447 }
448  
449 24 ▶ $port = $old_port if !defined $port and defined $old_port and length $old_port;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $port and defined $old_port and length $old_port 2 22 24
Condition83%5/6
not defined $port and defined $old_port and length $old_port
!ll&&!rl&&r
2202
not defined $port and defined $old_port
!ll&&!rl&&r
1842
MC/DC66%2/3
not defined $port and defined $old_port and length $old_port
not defined $port defined $old_port length $old_port
Truth table75%3/4
not(A) and B and C
A= not defined $portB= defined $old_portC= length $old_port
ABCresult
0XX0
10X0
1100
1111
450 24 ▶ $host = "[$host]" if $host =~ /:/ and $host !~ /^\[/;
Branch: 1 branch
BranchTrueFalseTotal
if $host =~ /:/ and not $host =~ /^\[/ 2 22 24
Condition100%3/3
$host =~ /:/ and not $host =~ /^\[/
!ll&&!rl&&r
2022
MC/DC100%2/2
$host =~ /:/ and not $host =~ /^\[/
$host =~ /:/ not $host =~ /^\[/
Truth table100%3/3
A and not(B)
A= $host =~ /:/B= not $host =~ /^\[/
ABresult
0X0
100
111
451  
452 24 ▶ return $prefix . "//$host" . ( defined $port ? ":$port" : '' ) . $service;
Branch: 1 branch
BranchTrueFalseTotal
defined $port ? : 20 4 24
453 }
454  
455 12 ▶ return (undef, 'a TNS descriptor (several ADDRESS entries make the host ambiguous)')
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /^\s*\(/ 4 8 12
456 if $rest =~ /^\s*\(/;
457  
458 8 ▶ return (undef, 'a name the Oracle client resolves (tnsnames.ora alias, SID or TWO_TASK), which names no host in the DSN')
Branch: 1 branch
BranchTrueFalseTotal
unless $rest =~ /=/ 6 2 8
459 unless $rest =~ /=/;
460  
461 2 return $self->next::method($driver, $dsn, $host, $port);
462 }
463  
464  
465 21 ▶sub relname_to_table_alias {
Subroutine relname_to_table_alias: called CC=1 SCAR=0.0
Pod documented
466 21 my $self = shift;
467 21 my ($relname, $join_count) = @_;
468 21 my $alias = $self->next::method(@_);
469 21 return $self->sql_maker->_shorten_identifier($alias);
470 }
471  
472  
473 # Internal helpers for LOBSupport role (called by the composed subs).
474 # The LOB-type predicates live in DBIO::Oracle::Type as the single source;
475 # these thin wrappers preserve the $self->_is_lob_type calling convention.
476 48 ▶sub _is_lob_type { DBIO::Oracle::Type::is_lob_type(@_) }
Subroutine _is_lob_type: called CC=1 SCAR=0.0
477 3 ▶sub _is_text_lob_type { DBIO::Oracle::Type::is_text_lob_type(@_) }
Subroutine _is_text_lob_type: called CC=1 SCAR=0.0
478  
479 23 1;
480  
481 __END__
« Oracle/Diff/Table.pm ↑ Summary Oracle/SQLMaker.pm »