Oracle/Storage.pm

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