blib/lib/DBIO/MySQL/Storage.pm

filter: Statementstmt 87.6% 228 / 260 Branchbran 88.1% 127 / 144 Conditioncond 70.8% 124 / 175 MC/DCmcdc 45.8% 44 / 96 Subroutinesub 78.2% 36 / 46 Podpod 93.3% 14 / 15 totaltotal 77.8% 573 / 736 CC 140 SCAR 30.2
CC
140
Cov
83%
_mysql_upsert_plan
58.0
_mask_error_values
30.0
_bind_host_into_dsn
15.0
CRAP 20.4
« blib/lib/DBIO/MySQL/Diff.pm ↑ Summary blib/lib/DBIO/MySQL/Deploy.pm »
1 package DBIO::MySQL::Storage;
2 # ABSTRACT: MySQL storage layer for DBIO
3  
4 50 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 50 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 50 our $VERSION = '0.900007';
8  
9 50 ▶use base qw/DBIO::Storage::DBI/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 50 ▶use DBIO::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 50 ▶use DBIO::Util qw( is_literal_value );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 50 ▶use DBIO::MySQL::MariaDBForkGuard ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 50 ▶use DBIO::MySQL::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 50 __PACKAGE__->register_driver('mysql' => __PACKAGE__);
17  
18 # Async is an explicit, per-connection mode (core ADR 0030): a connection opened
19 # with connect(..., { async => 'ev' }) resolves the 'ev' mode through the mode
20 # registry to the native MySQL EV backend below. Registering on this driver
21 # storage class MRO-shadows the generic modes (forked/future_io) registered on
22 # the base storage, so 'ev' picks the MySQL-specific backend. There is no auto-
23 # fallback and no silent degrade: a mode that is neither requested nor registered
24 # is simply unavailable, and requesting an unregistered/uninstalled mode croaks
25 # (see DBIO::Storage::DBI::_async_storage). This only stores the class name --
26 # DBIO::MySQL::EV::Storage (the optional dbio-mysql-ev dist) is loaded lazily
27 # on first use, so registering it here is safe when the dist is absent.
28 50 __PACKAGE__->register_async_mode( ev => 'DBIO::MySQL::EV::Storage' );
29  
30 # This is the ONLY async registration this driver needs, and it stays as-is
31 # under the storage-layer composition model (core karr #70): a mode maps to a
32 # transport BASE class, once, on this concrete driver storage. This dist writes
33 # storage_type only from its Schema components' connection() (DBIO::MySQL /
34 # DBIO::MySQL::MariaDB) -- choosing the driver BASE storage stays the driver's
35 # job. A driver EXTENSION does not subclass storage_type nor add a shadow
36 # register_async_mode / ::Async of its own: it registers a plain storage LAYER
37 # (DBIO::Schema::register_storage_layer) whose async mirror composes ON TOP of
38 # the resolved transport via DBIO::Storage::Composed. MySQL ships no such
39 # extension today, but the mechanism is core-provided and this reference driver
40 # honours it -- composition rides on top of this base; the mode->transport-base
41 # map does not grow per extension.
42  
43 0 ▶sub dbio_deploy_class { 'DBIO::MySQL::Deploy' }
Subroutine dbio_deploy_class: not called CC=1 SCAR=6.9
Pod undocumented
44  
45 50 __PACKAGE__->sql_maker_class('DBIO::MySQL::SQLMaker');
46 50 __PACKAGE__->sql_quote_char('`');
47 50 __PACKAGE__->datetime_parser_type('DateTime::Format::MySQL');
48  
49 50 __PACKAGE__->_use_multicolumn_in(1);
50  
51 # F02 / F10 -- transactional DDL. The capability asks exactly one question: can
52 # several DDL statements run inside ONE transaction and be taken back by a
53 # ROLLBACK? On both server products the answer is no, on every version, so this
54 # is a flat class-level fact and not a version gate like the set operations
55 # below. Every statement this dist's DDL and diff classes emit -- CREATE TABLE,
56 # CREATE VIEW, ALTER TABLE (ADD/DROP/MODIFY COLUMN, ADD/DROP FOREIGN KEY),
57 # CREATE INDEX, DROP INDEX, DROP TABLE -- is on both products' implicit-commit
58 # list: MySQL Reference Manual 15.3.3, "Statements That Cause an Implicit
59 # Commit" (https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html; the
60 # same section and the same list in 9.7), and MariaDB's "SQL statements Causing
61 # an Implicit Commit" (https://mariadb.com/docs/server/reference/sql-statements/
62 # transactions/sql-statements-that-cause-an-implicit-commit), which puts the
63 # consequence plainly: "All these statements cause an implicit commit before
64 # execution. This means that, even if the statement fails with an error, the
65 # transaction is committed. ... Such statements couldn't be rollbacked in any
66 # case."
67 #
68 # THE TRAP THIS COMMENT EXISTS FOR: atomic DDL is not transactional DDL, and
69 # the version numbers invite the confusion. MySQL 8.0 (Reference Manual 15.1.1,
70 # "Atomic Data Definition Statement Support",
71 # https://dev.mysql.com/doc/refman/8.0/en/atomic-ddl.html) and MariaDB 10.6.1
72 # (MDEV-17567, https://mariadb.com/docs/server/reference/sql-statements/
73 # data-definition/atomic-ddl) both made a SINGLE DDL statement crash-safe: an
74 # interrupted CREATE/ALTER/DROP no longer leaves a table without its data
75 # dictionary entry, an #sql-shadow file or a half-finished multi-table RENAME.
76 # That is a guarantee about a crash, not about a transaction, and MySQL's own
77 # manual says so in that very section: "Atomic DDL is not transactional DDL.
78 # DDL statements, atomic or otherwise, implicitly end any transaction that is
79 # active in the current session, as if you had done a COMMIT before executing
80 # the statement. This means that DDL statements cannot be performed within
81 # another transaction".
82 #
83 # So reading the server version and "tidying" the 0 below into a 1 buys nothing
84 # and costs the only thing that is left. It switches on the bracketed branch of
85 # DBIO::Deploy::Base::_execute_ddl, which wraps the statement loop in
86 # $storage->txn_do: the BEGIN goes out first and is committed away by the very
87 # next CREATE TABLE, so the closing COMMIT commits nothing that was still open
88 # and a ROLLBACK on failure takes back nothing at all. Statements 1..6 of a
89 # failing batch of 12 stay applied, exactly as they do today. What does change
90 # is that core's one-time "non-transactional DDL on ..." notice -- the only
91 # thing telling an operator that recovery here rests on re-running the upgrade
92 # against live state rather than on a rollback -- is no longer emitted. The
93 # warning goes quiet; the non-atomicity stays. Same reasoning applies to
94 # DBIO::DeploymentHandler, which reads this capability to decide whether a
95 # whole upgrade can run atomically, and to DBIO::Storage::Async, which declares
96 # nothing of its own and delegates the question to this class.
97 #
98 # Declared in tier 2 (__PACKAGE__->_use_X), NOT in tier 3 like the set-
99 # operation flags below, and the reason that drives those flags does not
100 # carry: core names this exact case -- "this engine commits DDL implicitly" --
101 # as its tier-2 example (DBIO::Storage::DBI::Capabilities, "Which tier a
102 # driver writes to"), and unlike the set operations this answer is the
103 # RESTRICTIVE one and identical to core's default, so losing it could at
104 # worst land on the same 0. Tier 2 is also what makes the declaration
105 # readable as a class method, which is the only way to tell a declared 0 from
106 # an inherited one -- t/58-deploy-transactional-ddl.t pins both.
107 #
108 # On the shared class, since which commit semantics DDL carries is a fact about
109 # the SERVER and not about the DBD; DBIO::MySQL::Storage::MariaDB is the
110 # DBD::MariaDB binding and inherits this rather than repeating it (karr k28,
111 # this dist's ADR 0001).
112 50 __PACKAGE__->_use_transactional_ddl(0);
113  
114 # ADR 0036: INSERT ... ON DUPLICATE KEY UPDATE has been in MySQL since 4.1 and
115 # in every MariaDB, so the capability is a flat class-level fact rather than a
116 # version gate. The ADR's hard precondition for declaring it -- "only if the
117 # identity handed back is provably the row that was written" -- is what
118 # L</insert> and L</_mysql_upsert_plan> below exist for: on the table shapes
119 # where this engine cannot name the written row, the primary key is withheld
120 # so core returns undef (or throws for result => 'row_or_die') instead of
121 # confidently handing back an unrelated row.
122 50 __PACKAGE__->_use_supports_upsert(1);
123  
124 # ADR 0037: results_exist and its two siblings are gated on this, and the gate
125 # means "somebody checked", not merely "the hook was overridden". It was
126 # checked: the base _exists_value_sql rendering is accepted by both server
127 # products this dist serves, so the hook is deliberately NOT overridden here.
128 # See the "The base EXISTS rendering is right for both server products"
129 # section below for what was checked and against what.
130 50 __PACKAGE__->_use_supports_exists_query(1);
131  
132 # ADR 0039 section 7 -- which set operations the server at the other end has.
133 # Two facts, because the two products drew two different lines and one boolean
134 # cannot express a MariaDB 10.3/10.4, which has INTERSECT and EXCEPT but not
135 # their ALL forms. Both default to AVAILABLE: every non-EOL release of either
136 # product has all six, so a gate defaulting to 0 would refuse an operation that
137 # works on essentially the entire installed base. A deployment pinned to an
138 # older server turns the relevant one off and trades a syntax error from the
139 # server for a local exception naming the boundary -- see the "Set operations"
140 # section below and _set_operation_keyword.
141 #
142 # Declared as _determine_supports_*, NOT as __PACKAGE__->_use_*(1). _use_X is
143 # the CALLER's force slot, and this driver declares the PERMISSIVE answer to
144 # both set-operator capabilities -- INTERSECT/EXCEPT and their ALL forms are
145 # present on every supported release of either product, while core's default
146 # is the restrictive 0. The determination tier is where a permissive answer
147 # survives contact with a caller: it is the structural fallback, so a caller
148 # who forces a capability off and later clears the force (_use_X(undef))
149 # always lands back on the driver's 1, never on core's 0. Had the declaration
150 # sat in the force slot, an unclearable force would have silently turned four
151 # working operations off for the life of the storage. Both tiers are pinned
152 # static rather than version-probing, which is the whole constraint of ADR 0039
153 # section 7 and is nailed shut at the spot where a future author would reach
154 # for _server_info.
155 50 __PACKAGE__->mk_group_accessors( dbms_capability => '_supports_set_operator_intersect_except' );
156 50 __PACKAGE__->mk_group_accessors( use_dbms_capability => '_use_set_operator_intersect_except' );
157 4 ▶sub _determine_supports_set_operator_intersect_except { 1 }
Subroutine _determine_supports_set_operator_intersect_except: called CC=1 SCAR=0.0
158  
159 50 __PACKAGE__->mk_group_accessors( dbms_capability => '_supports_set_operator_all_family' );
160 50 __PACKAGE__->mk_group_accessors( use_dbms_capability => '_use_set_operator_all_family' );
161 4 ▶sub _determine_supports_set_operator_all_family { 1 }
Subroutine _determine_supports_set_operator_all_family: called CC=1 SCAR=0.0
162  
163  
164 # ADR 0039 -- the keyword the six DBIO::ResultSet set operations join their
165 # operands with, and the seam that refuses the four neither product always had.
166 # Purely a refusal seam here: both MySQL and MariaDB use the ANSI spelling for
167 # every operation they have, so every path below ends in next::method.
168 #
169 # Deliberately a static class fact with no version probe. ResultSet's
170 # _set_operation bakes the keyword into a literal from clause at construction
171 # time, so a runtime-resolved keyword is not expressible at all -- and asking
172 # the server which product and version it is would open a connection during
173 # query build, purely in order to throw (ADR 0039 section 7). The two
174 # capabilities declared at the top of this class are what a deployment answers
175 # with instead; see the "Set operations" POD section for the version table.
176 41 ▶sub _set_operation_keyword {
Subroutine _set_operation_keyword: called CC=11 SCAR=24.0
177 41 my ($self, $op) = @_;
178  
179 # An undefined $op is core's programming error, and core's throw is the one
180 # that names it. Guard first so we do not warn on the eq below on the way
181 # there (the shape core's own POD example carries).
182 41 ▶ return $self->next::method($op) unless defined $op;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $op 1 40 41
183  
184 # UNION and UNION ALL predate anything this driver can meet on either
185 # product. Only the other four have a boundary, so only they are asked about.
186 40 ▶ if ( $op eq 'except' or $op eq 'intersect'
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "except" or $op eq "intersect" or $op eq "except_all" or $op eq "intersect_all") 28 12 40
Condition100%9/9
$op eq "except" or $op eq "intersect" or $op eq "except_all" or $op eq "intersect_all"
l!l&&r!l&&!r
22612
$op eq "except" or $op eq "intersect" or $op eq "except_all"
l!l&&r!l&&!r
13918
$op eq "except" or $op eq "intersect"
l!l&&r!l&&!r
8527
MC/DC100%4/4
$op eq "except" or $op eq "intersect" or $op eq "except_all" or $op eq "intersect_all"
$op eq "except" $op eq "intersect" $op eq "except_all" $op eq "intersect_all"
Truth table100%5/5
A or B or C or D
A= $op eq "except"B= $op eq "intersect"C= $op eq "except_all"D= $op eq "intersect_all"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
187 or $op eq 'except_all' or $op eq 'intersect_all') {
188  
189 # The outer boundary first: without INTERSECT/EXCEPT at all there is no
190 # ALL form of them either, so this check subsumes the one below and a
191 # deployment that only turned off the outer switch still gets a coherent
192 # answer for all four.
193 28 ▶ $self->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_use_set_operator_intersect_except 6 22 28
194 "This server has no INTERSECT / EXCEPT, so this driver refuses "
195 . "\$rs->$op. MySQL gained both in 8.0.31 (Reference Manual 15.2.4 and "
196 . "15.2.8, WL #349) and MariaDB in 10.3 (MDEV-10141); this deployment has "
197 . "declared its server older than that with "
198 . "DBIO::MySQL::Storage->_use_set_operator_intersect_except(0). "
199 . "_set_operation_keyword must answer as a static class fact -- "
200 . "DBIO::ResultSet::_set_operation bakes the keyword into the query while "
201 . "it is being built -- so this driver cannot check the server version "
202 . "here, and the declaration is the only thing it can read (ADR 0039 "
203 . "section 7). Pass (1) to undo it, or use \$rs->union / \$rs->union_all, "
204 . "which every version of both products has."
205 ) unless $self->_use_set_operator_intersect_except;
206  
207 22 ▶ $self->throw_exception(
Branch: 2 branches
BranchTrueFalseTotal
if $op eq "except_all" || $op eq "intersect_all" and not $self->_use_set_operator_all_family 7 15 22
$op eq 'except_all' ? : 5 2 7
Condition100%6/6
$op eq "except_all" || $op eq "intersect_all" and not $self->_use_set_operator_all_family
!ll&&!rl&&r
967
$op eq "except_all" or $op eq "intersect_all"
l!l&&r!l&&!r
859
MC/DC100%3/3
$op eq "except_all" || $op eq "intersect_all" and not $self->_use_set_operator_all_family
$op eq "except_all" $op eq "intersect_all" not $self->_use_set_operator_all_family
Truth table100%5/5
A or B and not(C)
A= $op eq "except_all"B= $op eq "intersect_all"C= not $self->_use_set_operator_all_family
ABCresult
00X0
1X00
0100
1X11
0111
208 "This server has no INTERSECT ALL / EXCEPT ALL, so this driver refuses "
209 . "\$rs->$op -- \$rs->" . ($op eq 'except_all' ? 'except' : 'intersect')
210 . " is unaffected, but it is a different operation, not a fallback: it "
211 . "collapses duplicates. MySQL got the ALL forms together with the "
212 . "DISTINCT ones in 8.0.31 (WL #349), MariaDB only two releases later in "
213 . "10.5.0 (MDEV-18844), having had the DISTINCT forms since 10.3; this "
214 . "deployment has declared its server inside that gap with "
215 . "DBIO::MySQL::Storage->_use_set_operator_all_family(0). "
216 . "_set_operation_keyword must answer as a static class fact and cannot "
217 . "check the server version here (ADR 0039 section 7), so the declaration "
218 . "is the only thing it can read. Pass (1) to undo it."
219 ) if ( $op eq 'except_all' or $op eq 'intersect_all' )
220 and ! $self->_use_set_operator_all_family;
221 }
222  
223 # Both products spell all six the ANSI way, so the base map answers every
224 # operation this class did not refuse -- and an unknown $op lands on core's
225 # throw there rather than being invented here.
226 27 return $self->next::method($op);
227 }
228  
229 0 ▶sub with_deferred_fk_checks {
Subroutine with_deferred_fk_checks: not called CC=1 SCAR=6.9
Pod documented
230 0 my ($self, $sub) = @_;
231  
232 0 $self->_do_query('SET FOREIGN_KEY_CHECKS = 0');
233 0 $sub->();
234 0 $self->_do_query('SET FOREIGN_KEY_CHECKS = 1');
235 }
236  
237  
238 0 ▶sub connect_call_set_strict_mode {
Subroutine connect_call_set_strict_mode: not called CC=1 SCAR=6.9
Pod documented
239 0 my $self = shift;
240  
241 # the @@sql_mode puts back what was previously set on the session handle
242 0 $self->_do_query(q|SET SQL_MODE = CONCAT('ANSI,TRADITIONAL,ONLY_FULL_GROUP_BY,', @@sql_mode)|);
243 0 $self->_do_query(q|SET SQL_AUTO_IS_NULL = 0|);
244 }
245  
246  
247 # Each DBD's name for what this dist asks of it by a DBD-private name, keyed the
248 # way DBI names the DBD in $dbh->{Driver}{Name}: the two attributes the sync
249 # storage reads or writes, and the async binding the future_io transport
250 # drives (karr k59, k60). One table for both, so the two cannot disagree about
251 # a DBD.
252 50 my %DBD_ATTRIBUTE = (
253 mysql => {
254 auto_reconnect => 'mysql_auto_reconnect',
255 insertid => 'mysql_insertid',
256 async => 'async',
257 socket_fd => 'mysql_fd',
258 async_ready => 'mysql_async_ready',
259 async_result => 'mysql_async_result',
260 serverinfo => 'mysql_serverinfo',
261 },
262 MariaDB => {
263 auto_reconnect => 'mariadb_auto_reconnect',
264 insertid => 'mariadb_insertid',
265 async => 'mariadb_async',
266 socket_fd => 'mariadb_sockfd',
267 async_ready => 'mariadb_async_ready',
268 async_result => 'mariadb_async_result',
269 serverinfo => 'mariadb_serverinfo',
270 },
271 );
272  
273  
274 3994 ▶sub _dbd_attribute {
Subroutine _dbd_attribute: called CC=5 SCAR=16.1
275 3994 my ($self, $dbd, $what) = @_;
276  
277 3994 ▶ my $attr = ( $DBD_ATTRIBUTE{ $dbd // '' } || {} )->{$what};
Condition100%4/4
$DBD_ATTRIBUTE{$dbd // ''} || {}
l!l
394648
$dbd // ""
l!l
395143
MC/DC100%1/1
$DBD_ATTRIBUTE{$dbd // ''} || {}
$DBD_ATTRIBUTE{$dbd // ''}
MC/DC100%1/1
$dbd // ""
$dbd
Truth table100%2/2
A
A= $DBD_ATTRIBUTE{$dbd // ''}
Aresult
11
00
Truth table100%2/2
A
A= $dbd
Aresult
11
00
278 3994 ▶ return $attr if defined $attr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $attr 3946 48 3994
279  
280 48 ▶ $self->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
defined $dbd ? : 5 43 48
281 "DBIO::MySQL::Storage knows the '$what' name of DBD::mysql and "
282 . 'DBD::MariaDB only, and this connection belongs to '
283 . ( defined $dbd ? "DBD::$dbd" : 'no DBD driver it can name' )
284 );
285 }
286  
287  
288 23 ▶sub _dbd_attribute_prefixes {
Subroutine _dbd_attribute_prefixes: called CC=5 SCAR=16.1
289 23 my ($self, $driver) = @_;
290  
291 23 ▶ return 'mariadb_' if defined $driver && $driver eq 'MariaDB';
Branch: 1 branch
BranchTrueFalseTotal
if defined $driver and $driver eq "MariaDB" 12 11 23
Condition100%3/3
defined $driver and $driver eq "MariaDB"
!ll&&!rl&&r
11012
MC/DC100%2/2
defined $driver and $driver eq "MariaDB"
defined $driver $driver eq "MariaDB"
Truth table100%3/3
A and B
A= defined $driverB= $driver eq "MariaDB"
ABresult
0X0
100
111
292 11 ▶ return 'mysql_' if defined $driver && $driver eq 'mysql';
Branch: 1 branch
BranchTrueFalseTotal
if defined $driver and $driver eq "mysql" 9 2 11
Condition100%3/3
defined $driver and $driver eq "mysql"
!ll&&!rl&&r
119
MC/DC100%2/2
defined $driver and $driver eq "mysql"
defined $driver $driver eq "mysql"
Truth table100%3/3
A and B
A= defined $driverB= $driver eq "mysql"
ABresult
0X0
100
111
293 2 return $self->next::method($driver);
294 }
295  
296  
297 2 ▶sub _dbh_last_insert_id {
Subroutine _dbh_last_insert_id: called CC=1 SCAR=0.0
298 2 my ($self, $dbh) = @_;
299  
300 2 $dbh->{ $self->_dbd_attribute($dbh->{Driver}{Name}, 'insertid') };
301 }
302  
303  
304 26 ▶sub _run_connection_actions {
Subroutine _run_connection_actions: called CC=4 SCAR=13.9
305 26 my $self = shift;
306  
307 26 my $dbh = $self->_dbh;
308 26 my $reconnect = $self->_dbd_attribute($dbh->{Driver}{Name}, 'auto_reconnect');
309  
310 25 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->{$reconnect} and not exists $self->_dbio_connect_attributes->{$reconnect}) 20 5 25
Condition100%3/3
$dbh->{$reconnect} and not exists $self->_dbio_connect_attributes->{$reconnect}
!ll&&!rl&&r
1420
MC/DC100%2/2
$dbh->{$reconnect} and not exists $self->_dbio_connect_attributes->{$reconnect}
$dbh->{$reconnect} not exists $self->_dbio_connect_attributes->{$reconnect}
Truth table100%3/3
A and not(B)
A= $dbh->{$reconnect}B= not exists $self->_dbio_connect_attributes->{$reconnect}
ABresult
0X0
100
111
311 $dbh->{$reconnect}
312 and
313 ! exists $self->_dbio_connect_attributes->{$reconnect}
314 ) {
315 20 $dbh->{$reconnect} = 0;
316 }
317  
318 # A forked child's exit must not close this process's connections
319 # (karr k56, ADR 0009).
320 25 ▶ DBIO::MySQL::MariaDBForkGuard->install if $dbh->{Driver}{Name} eq 'MariaDB';
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->{"Driver"}{"Name"} eq "MariaDB" 13 12 25
321  
322 # Before the connection actions of the caller, so on_connect_do and
323 # on_connect_call can still set the mode they want (karr k120).
324 25 session_setup($dbh);
325  
326 25 $self->next::method(@_);
327 }
328  
329  
330 465 ▶sub session_setup {
Subroutine session_setup: called CC=1 SCAR=0.0
Pod documented
331 465 my ($dbh) = @_;
332 465 $dbh->do(strict_sql_mode_statement());
333 465 return;
334 }
335  
336  
337 470 ▶sub strict_sql_mode_statement {
Subroutine strict_sql_mode_statement: called CC=1 SCAR=0.0
Pod documented
338 470 return q{SET SESSION sql_mode = IF(}
339 . q{FIND_IN_SET('STRICT_ALL_TABLES', @@SESSION.sql_mode) OR }
340 . q{FIND_IN_SET('STRICT_TRANS_TABLES', @@SESSION.sql_mode), }
341 . q{@@SESSION.sql_mode, }
342 . q{CONCAT_WS(',', NULLIF(@@SESSION.sql_mode, ''), 'STRICT_ALL_TABLES'))};
343 }
344  
345  
346 75 ▶sub bind_attribute_by_data_type {
Subroutine bind_attribute_by_data_type: called CC=3 SCAR=11.0
Pod documented
347 75 my ($self, $data_type) = @_;
348 75 ▶ return { TYPE => DBI::SQL_BINARY() }
Branch: 1 branch
BranchTrueFalseTotal
if defined $data_type and $data_type =~ /\A(?:(?:tiny|medium|long)?blob|(?:var)?binary|bytea)\z/i 11 64 75
Condition66%2/3
defined $data_type and $data_type =~ /\A(?:(?:tiny|medium|long)?blob|(?:var)?binary|bytea)\z/i
!ll&&!rl&&r
06411
MC/DC50%1/2
defined $data_type and $data_type =~ /\A(?:(?:tiny|medium|long)?blob|(?:var)?binary|bytea)\z/i
defined $data_type $data_type =~ /\A(?:(?:tiny|medium|long)?blob|(?:var)?binary|bytea)\z/i
Truth table66%2/3
A and B
A= defined $data_typeB= $data_type =~ /\A(?:(?:tiny|medium|long)?blob|(?:var)?binary|bytea)\z/i
ABresult
0X0
100
111
349 if defined $data_type
350 && $data_type =~ /\A(?:(?:tiny|medium|long)?blob|(?:var)?binary|bytea)\z/i;
351 64 return undef;
352 }
353  
354  
355 7 ▶sub _adjust_bind_values {
Subroutine _adjust_bind_values: called CC=1 SCAR=0.0
356 7 my ($self, $sth, $bind, $bind_attrs) = @_;
357 7 return text_binds($self->_dbh, $bind, $bind_attrs);
358 }
359  
360  
361 500 ▶sub text_binds {
Subroutine text_binds: called CC=12 SCAR=24.9
Pod documented
362 500 my ($dbh, $bind, $bind_attrs) = @_;
363  
364 return $bind unless $dbh && ($dbh->{Driver}{Name} // '') eq 'mysql'
365 500 ▶ && ($dbh->{mysql_enable_utf8mb4} || $dbh->{mysql_enable_utf8});
Branch: 1 branch
BranchTrueFalseTotal
unless $dbh and ($dbh->{"Driver"}{"Name"} // "") eq "mysql" and $dbh->{"mysql_enable_utf8mb4"} || $dbh->{"mysql_enable_utf8"} 495 5 500
Condition72%8/11
$dbh and ($dbh->{"Driver"}{"Name"} // "") eq "mysql" and $dbh->{"mysql_enable_utf8mb4"} || $dbh->{"mysql_enable_utf8"}
!ll&&!rl&&r
2012945
$dbh and ($dbh->{"Driver"}{"Name"} // "") eq "mysql"
!ll&&!rl&&r
0201299
$dbh->{"Driver"}{"Name"} // ""
l!l
5000
$dbh->{"mysql_enable_utf8mb4"} or $dbh->{"mysql_enable_utf8"}
l!l&&r!l&&!r
50294
MC/DC25%1/4
$dbh and ($dbh->{"Driver"}{"Name"} // "") eq "mysql" and $dbh->{"mysql_enable_utf8mb4"} || $dbh->{"mysql_enable_utf8"}
$dbh $dbh->{"Driver"}{"Name"} $dbh->{"mysql_enable_utf8mb4"} $dbh->{"mysql_enable_utf8"}
Truth table40%2/5
A and B and C or D
A= $dbhB= $dbh->{"Driver"}{"Name"}C= $dbh->{"mysql_enable_utf8mb4"}D= $dbh->{"mysql_enable_utf8"}
ABCDresult
0XXX0
10XX0
11000
111X1
11011
366  
367 5 my @copy = @$bind;
368 5 for my $i (0 .. $#copy) {
369 16 my $v = $copy[$i][1];
370 16 ▶ next if !defined $v || ref $v || utf8::is_utf8($v)
Branch: 1 branch
BranchTrueFalseTotal
if not defined $v or ref $v or utf8::is_utf8($v) or not $v =~ /[^\x00-\x7F]/ or $bind_attrs->[$i] 11 5 16
Condition100%12/12
not defined $v or ref $v or utf8::is_utf8($v) or not $v =~ /[^\x00-\x7F]/ or $bind_attrs->[$i]
l!l&&r!l&&!r
835
not defined $v or ref $v or utf8::is_utf8($v) or not $v =~ /[^\x00-\x7F]/
l!l&&r!l&&!r
538
not defined $v or ref $v or utf8::is_utf8($v)
l!l&&r!l&&!r
4111
not defined $v or ref $v
l!l&&r!l&&!r
2212
MC/DC100%5/5
not defined $v or ref $v or utf8::is_utf8($v) or not $v =~ /[^\x00-\x7F]/ or $bind_attrs->[$i]
not defined $v ref $v utf8::is_utf8($v) not $v =~ /[^\x00-\x7F]/ $bind_attrs->[$i]
Truth table100%6/6
not(A) or B or C or not(D) or E
A= not defined $vB= ref $vC= utf8::is_utf8($v)D= not $v =~ /[^\x00-\x7F]/E= $bind_attrs->[$i]
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
371 || $v !~ /[^\x00-\x7F]/ || $bind_attrs->[$i];
372 5 utf8::upgrade($v);
373 5 $copy[$i] = [ $copy[$i][0], $v ];
374 }
375 5 return \@copy;
376 }
377  
378  
379 59 ▶sub _get_server_version {
Subroutine _get_server_version: called CC=3 SCAR=11.0
380 59 my $self = shift;
381  
382 59 my ($version) = eval { $self->_get_dbh->selectrow_array('SELECT VERSION()') };
383  
384 59 ▶ return $version if defined $version and length $version;
Branch: 1 branch
BranchTrueFalseTotal
if defined $version and length $version 57 2 59
Condition66%2/3
defined $version and length $version
!ll&&!rl&&r
2057
MC/DC50%1/2
defined $version and length $version
defined $version length $version
Truth table66%2/3
A and B
A= defined $versionB= length $version
ABresult
0X0
100
111
385  
386 2 return $self->next::method(@_);
387 }
388  
389  
390 439 ▶sub _is_mariadb {
Subroutine _is_mariadb: called CC=3 SCAR=11.1
391 439 my $self = shift;
392  
393 439 ▶ return ( ($self->_server_info->{dbms_version} // '') =~ /mariadb/i ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
($self->_server_info->{'dbms_version'} // '') =~ /mariadb/i ? : 80 359 439
Condition50%1/2
$self->_server_info->{"dbms_version"} // ""
l!l
4390
MC/DC0%0/1
$self->_server_info->{"dbms_version"} // ""
$self->_server_info->{"dbms_version"}
Truth table50%1/2
A
A= $self->_server_info->{"dbms_version"}
Aresult
11
00
394 }
395  
396  
397 44 ▶sub _determine_supports_insert_returning {
Subroutine _determine_supports_insert_returning: called CC=4 SCAR=13.9
398 44 my $self = shift;
399  
400 44 ▶ return 0 unless $self->_is_mariadb;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_mariadb 20 24 44
401  
402 24 ▶ return ( ($self->_server_info->{normalized_dbms_version} // 0) >= 10.005 )
Branch: 1 branch
BranchTrueFalseTotal
($self->_server_info->{'normalized_dbms_version'} // 0) >= 10.005 ? : 20 4 24
Condition50%1/2
$self->_server_info->{"normalized_dbms_version"} // 0
l!l
240
MC/DC0%0/1
$self->_server_info->{"normalized_dbms_version"} // 0
$self->_server_info->{"normalized_dbms_version"}
Truth table50%1/2
A
A= $self->_server_info->{"normalized_dbms_version"}
Aresult
11
00
403 ? 1 : 0;
404 }
405  
406 # we need to figure out what mysql version we're running
407 157 ▶sub sql_maker {
Subroutine sql_maker: called CC=4 SCAR=14.4
Pod documented
408 157 my $self = shift;
409  
410 # it is critical to get the version *before* calling next::method
411 # otherwise the potential connect will obliterate the sql_maker
412 # next::method will populate in the _sql_maker accessor
413 157 my $mysql_ver = $self->_server_info->{normalized_dbms_version};
414  
415 157 my $sm = $self->next::method(@_);
416  
417 # MySQL always uses backtick quoting — ensure it is active even when
418 # the caller did not pass quote_names in connect_info.
419 157 ▶ $sm->{quote_char} //= $self->sql_quote_char;
Condition33%1/3
$sm->{"quote_char"} //= $self->sql_quote_char
l!l&&r!l&&!r
15700
MC/DC0%0/2
$sm->{"quote_char"} //= $self->sql_quote_char
$sm->{"quote_char"} $self->sql_quote_char
Truth table33%1/3
A //= B
A= $sm->{"quote_char"}B= $self->sql_quote_char
ABresult
1X1
011
000
420 157 ▶ $sm->{name_sep} //= $self->sql_name_sep;
Condition33%1/3
$sm->{"name_sep"} //= $self->sql_name_sep
l!l&&r!l&&!r
15700
MC/DC0%0/2
$sm->{"name_sep"} //= $self->sql_name_sep
$sm->{"name_sep"} $self->sql_name_sep
Truth table33%1/3
A //= B
A= $sm->{"name_sep"}B= $self->sql_name_sep
ABresult
1X1
011
000
421  
422 # mysql 3 does not understand a bare JOIN
423 157 ▶ $sm->{_default_jointype} = 'INNER' if $mysql_ver < 4;
Branch: 1 branch
BranchTrueFalseTotal
if $mysql_ver < 4 77 80 157
424  
425 # ADR 0036: which spelling of "the value that was attempted to be inserted"
426 # this server understands in an ON DUPLICATE KEY UPDATE set. The storage is
427 # the only side that can ask the server, so it decides and the maker only
428 # renders (see DBIO::MySQL::SQLMaker/_insert_row_alias).
429 157 $sm->{_upsert_row_alias} = $self->_upsert_row_alias;
430  
431 # karr #30: which locking-read grammar the server has. Same split as the line
432 # above -- the storage asks the server, the maker renders what it is told
433 # (see DBIO::MySQL::SQLMaker/_lock_dialect).
434 157 $sm->{_lock_dialect} = $self->_lock_dialect;
435  
436 157 $sm;
437 }
438  
439  
440 195 ▶sub _lock_dialect {
Subroutine _lock_dialect: called CC=12 SCAR=25.7
441 195 my $self = shift;
442  
443 195 ▶ my $info = $self->_server_info || {};
Condition50%1/2
$self->_server_info || {}
l!l
1950
MC/DC0%0/1
$self->_server_info || {}
$self->_server_info
Truth table50%1/2
A
A= $self->_server_info
Aresult
11
00
444 195 ▶ my $ver = $info->{normalized_dbms_version} // 0;
Condition50%1/2
$info->{"normalized_dbms_version"} // 0
l!l
1950
MC/DC0%0/1
$info->{"normalized_dbms_version"} // 0
$info->{"normalized_dbms_version"}
Truth table50%1/2
A
A= $info->{"normalized_dbms_version"}
Aresult
11
00
445  
446 # A version we could not read is treated as current, on both branches; see
447 # the POD above. MariaDB answers the two modifiers separately because it
448 # shipped them separately: NOWAIT in 10.3, SKIP LOCKED in 10.6 (karr #38).
449 return {
450 share => 'LOCK IN SHARE MODE',
451 of => 0,
452 nowait => ( $ver and $ver < 10.003 ) ? 0 : 1,
453 skip_locked => ( $ver and $ver < 10.006 ) ? 0 : 1,
454 195 ▶ server => 'a MariaDB (' . ($info->{dbms_version} // '?') . ')',
Branch: 3 branches
BranchTrueFalseTotal
if $self->_is_mariadb 32 163 195
$ver && $ver < 10.003 ? : 3 29 32
$ver && $ver < 10.006 ? : 9 23 32
Condition62%5/8
$ver and $ver < "10.003"
!ll&&!rl&&r
0293
$ver and $ver < "10.006"
!ll&&!rl&&r
0239
$info->{"dbms_version"} // "?"
l!l
320
MC/DC50%1/2
$ver and $ver < "10.003"
$ver $ver < "10.003"
MC/DC50%1/2
$ver and $ver < "10.006"
$ver $ver < "10.006"
MC/DC0%0/1
$info->{"dbms_version"} // "?"
$info->{"dbms_version"}
Truth table66%2/3
A and B
A= $verB= $ver < "10.003"
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= $verB= $ver < "10.006"
ABresult
0X0
100
111
Truth table50%1/2
A
A= $info->{"dbms_version"}
Aresult
11
00
455 } if $self->_is_mariadb;
456  
457 return {
458 share => 'LOCK IN SHARE MODE',
459 of => 0,
460 nowait => 0,
461 skip_locked => 0,
462 163 ▶ server => 'a MySQL older than 8.0.1 (' . ($info->{dbms_version} // '?') . ')',
Branch: 1 branch
BranchTrueFalseTotal
if $ver and $ver < "8.000001" 39 124 163
Condition80%4/5
$ver and $ver < "8.000001"
!ll&&!rl&&r
735139
$info->{"dbms_version"} // "?"
l!l
390
MC/DC100%2/2
$ver and $ver < "8.000001"
$ver $ver < "8.000001"
MC/DC0%0/1
$info->{"dbms_version"} // "?"
$info->{"dbms_version"}
Truth table100%3/3
A and B
A= $verB= $ver < "8.000001"
ABresult
0X0
100
111
Truth table50%1/2
A
A= $info->{"dbms_version"}
Aresult
11
00
463 } if $ver and $ver < 8.000001;
464  
465 return {
466 124 share => 'FOR SHARE',
467 of => 1,
468 nowait => 1,
469 skip_locked => 1,
470 server => 'a MySQL 8.0.1 or newer',
471 };
472 }
473  
474  
475 169 ▶sub _upsert_row_alias {
Subroutine _upsert_row_alias: called CC=5 SCAR=16.3
476 169 my $self = shift;
477  
478 169 ▶ return undef if $self->_is_mariadb;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_mariadb 12 157 169
479  
480 157 ▶ my $info = $self->_server_info || {};
Condition50%1/2
$self->_server_info || {}
l!l
1570
MC/DC0%0/1
$self->_server_info || {}
$self->_server_info
Truth table50%1/2
A
A= $self->_server_info
Aresult
11
00
481  
482 157 ▶ return undef unless ($info->{normalized_dbms_version} // 0) >= 8.000020;
Branch: 1 branch
BranchTrueFalseTotal
unless ($info->{"normalized_dbms_version"} // 0) >= "8.00002" 125 32 157
Condition50%1/2
$info->{"normalized_dbms_version"} // 0
l!l
1570
MC/DC0%0/1
$info->{"normalized_dbms_version"} // 0
$info->{"normalized_dbms_version"}
Truth table50%1/2
A
A= $info->{"normalized_dbms_version"}
Aresult
11
00
483  
484 32 return 'new';
485 }
486  
487  
488 31 ▶sub insert {
Subroutine insert: called CC=6 SCAR=18.0
Pod documented
489 31 my ($self, $source, $to_insert, $opts) = @_;
490  
491 31 ▶ my $on_conflict = $opts ? $opts->{on_conflict} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$opts ? : 30 1 31
492 31 ▶ return $self->next::method($source, $to_insert, $opts) unless $on_conflict;
Branch: 1 branch
BranchTrueFalseTotal
unless $on_conflict 1 30 31
493  
494 30 my $plan = $self->_mysql_upsert_plan($source, $to_insert, $opts);
495  
496 # the renderer gets the two MySQL-private keys it cannot derive itself;
497 # localised so the caller's structure comes back out unchanged
498 26 local $opts->{on_conflict} = { %$on_conflict, %{ $plan->{extra} } };
499  
500 26 my $returned = $self->next::method($source, $to_insert, $opts);
501  
502 25 ▶ return $returned if $plan->{nameable} or ! $plan->{wants_identity};
Branch: 1 branch
BranchTrueFalseTotal
if $plan->{"nameable"} or not $plan->{"wants_identity"} 18 7 25
Condition66%2/3
$plan->{"nameable"} or not $plan->{"wants_identity"}
l!l&&r!l&&!r
1807
MC/DC50%1/2
$plan->{"nameable"} or not $plan->{"wants_identity"}
$plan->{"nameable"} not $plan->{"wants_identity"}
Truth table66%2/3
A or not(B)
A= $plan->{"nameable"}B= not $plan->{"wants_identity"}
ABresult
1X1
011
000
503  
504 # Core's nameability test is exactly "did every primary key column come
505 # back for the written row". It did not: whatever primary key value is in
506 # hand belongs to the row we *tried* to insert, not necessarily to the row
507 # the engine touched. Withholding it is the difference between undef and a
508 # confidently wrong row.
509 7 delete @{$returned}{ @{ $plan->{primary_columns} } };
510  
511 # The default result shape is the one value nobody types, so only the
512 # runtime can teach the caller who needs teaching. Core carps too, but it
513 # can only report the symptom (no primary key came back); the reason is a
514 # MySQL grammar fact and this is the layer that knows it.
515 7 ▶ carp_once($plan->{reason}) if defined $plan->{reason};
Branch: 1 branch
BranchTrueFalseTotal
if defined $plan->{"reason"} 7 0 7
516  
517 7 return $returned;
518 }
519  
520 # Everything ADR 0036 needs decided before the statement runs, derived from
521 # the ResultSource alone. Returns:
522 #
523 # nameable => can the written row be named afterwards
524 # wants_identity => is anybody asking (false for result => 'void'/'count')
525 # primary_columns => \@pk, the columns to withhold when not nameable
526 # extra => private on_conflict keys for DBIO::MySQL::SQLMaker
527 # reason => the carp text for the unresolvable path, or undef
528 #
529 # The options may carry `returning => 0`, a hint from the reader of the
530 # result: "I read LAST_INSERT_ID(), not RETURNING". Without it (key absent or
531 # true) nothing changes; with it the plan takes the LAST_INSERT_ID(pk) idiom
532 # on MariaDB 10.5+ as well, where it is otherwise left out.
533 #
534 # Throws for a conflict target this engine cannot honour.
535 45 ▶sub _mysql_upsert_plan {
Subroutine _mysql_upsert_plan: called CC=46 SCAR=40.6
536 45 my ($self, $source, $to_insert, $opts) = @_;
537  
538 45 my $on_conflict = $opts->{on_conflict};
539 45 ▶ my $sname = $source->source_name || $source->result_class || 'this result source';
Condition40%2/5
$source->source_name || $source->result_class || 'this result source'
l!l
450
$source->source_name or $source->result_class
l!l&&r!l&&!r
4500
MC/DC0%0/2
$source->source_name || $source->result_class || 'this result source'
$source->source_name $source->result_class
Truth table33%1/3
A or B
A= $source->source_nameB= $source->result_class
ABresult
1X1
011
000
540  
541 45 my @pk = $source->primary_columns;
542 45 my %declared = $source->unique_constraints;
543  
544 # Distinct unique indexes, keyed by their column set. The same columns
545 # declared under two names (a named constraint mirroring the primary key,
546 # as the core test schema's Artist does) is ONE index to the engine, and
547 # "is there more than one" is what everything below turns on.
548 45 my (%unique_cols, %unique_names);
549 45 for my $name (sort keys %declared) {
550 159 my $key = _mysql_colset_key(@{ $declared{$name} });
551 159 ▶ $unique_cols{$key} ||= [ @{ $declared{$name} } ];
Condition100%2/2
$unique_cols{$key} ||= [@{$declared{$name};}]
l!l
36123
MC/DC100%1/1
$unique_cols{$key} ||= [@{$declared{$name};}]
$unique_cols{$key}
Truth table100%2/2
A
A= $unique_cols{$key}
Aresult
11
00
552 159 push @{ $unique_names{$key} }, $name;
553 }
554 45 ▶ if (@pk) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pk) 45 0 45
555 45 my $key = _mysql_colset_key(@pk);
556 45 ▶ $unique_cols{$key} ||= [ @pk ];
Condition50%1/2
$unique_cols{$key} ||= [@pk]
l!l
450
MC/DC0%0/1
$unique_cols{$key} ||= [@pk]
$unique_cols{$key}
Truth table50%1/2
A
A= $unique_cols{$key}
Aresult
11
00
557 }
558  
559 45 ▶ my $pk_key = @pk ? _mysql_colset_key(@pk) : undef;
Branch: 1 branch
BranchTrueFalseTotal
@pk ? : 45 0 45
560  
561 # ---- the conflict target the caller ended up with
562  
563 45 my $target = $on_conflict->{target};
564 45 my (@target_cols, $target_key);
565 45 ▶ if (ref $target eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $target eq 'ARRAY') { } 6 39 45
elsif (ref $target eq 'HASH' and defined $target->{'constraint'}) { } 1 76 77
566 6 @target_cols = @$target;
567 }
568 ▶ elsif (ref $target eq 'HASH' and defined $target->{constraint}) {
Condition66%2/3
ref $target eq "HASH" and defined $target->{"constraint"}
!ll&&!rl&&r
3801
MC/DC50%1/2
ref $target eq "HASH" and defined $target->{"constraint"}
ref $target eq "HASH" defined $target->{"constraint"}
Truth table66%2/3
A and B
A= ref $target eq "HASH"B= defined $target->{"constraint"}
ABresult
0X0
100
111
569 1 @target_cols = $source->unique_constraint_columns($target->{constraint});
570 }
571 # anything else is 'any': the caller asked for the engine's own "whichever
572 # key collides", which is the one target shape MySQL can actually deliver
573 45 ▶ $target_key = _mysql_colset_key(@target_cols) if @target_cols;
Branch: 1 branch
BranchTrueFalseTotal
if @target_cols 7 38 45
574  
575 # ---- ADR 0036 section 1: a demanded target this engine cannot honour
576  
577 45 ▶ if (defined $target_key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $target_key) 7 38 45
578 7 my @others = grep { $_ ne $target_key } sort keys %unique_cols;
579  
580 7 ▶ if (@others) {
Branch: 1 branch
BranchTrueFalseTotal
if (@others) 4 3 7
581 my $others_desc = join '; ', map {
582 4 my $names = $unique_names{$_};
583 sprintf '%s(%s)',
584 ($names && @$names ? join('/', @$names) . ' ' : ''),
585 7 ▶ join(', ', @{ $unique_cols{$_} })
Branch: 1 branch
BranchTrueFalseTotal
$names && @$names ? : 7 0 7
Condition33%1/3
$names and @$names
!ll&&!rl&&r
007
MC/DC0%0/2
$names and @$names
$names @$names
Truth table33%1/3
A and B
A= $namesB= @$names
ABresult
0X0
100
111
586 } @others;
587  
588 4 $self->throw_exception(
589 "upsert() on $sname: MySQL cannot honour the requested conflict "
590 . 'target (' . join(', ', @target_cols) . '). ON DUPLICATE KEY UPDATE '
591 . 'has no conflict target in its grammar -- it fires on ANY primary or '
592 . "unique key collision -- and $sname has further unique key(s) besides "
593 . "the target: $others_desc. A collision on one of those would silently "
594 . 'update a row the target never named, where PostgreSQL and SQLite '
595 . "raise a unique violation for the same call. Pass "
596 . "conflict_target => 'any' to ask for MySQL's native \"whichever key "
597 . 'collides" behaviour deliberately, or target the only unique key of '
598 . 'the table.'
599 );
600 }
601 }
602  
603 # ---- ADR 0036 section 4: can the written row be named afterwards
604  
605 41 my $col_infos = $source->columns_info;
606  
607 # With a real target there is provably no other unique key (checked just
608 # above), so the collision can only have happened on it. With 'any' the
609 # target is only known when the table has exactly one unique key anyway.
610 41 ▶ my $effective_key = defined $target_key
Branch: 2 branches
BranchTrueFalseTotal
defined $target_key ? : 3 38 41
keys %unique_cols == 1 ? : 0 38 38
611 ? $target_key
612 : ( keys %unique_cols == 1 ? (keys %unique_cols)[0] : undef );
613  
614 # A primary key column is known client-side only when the caller supplied a
615 # plain value: a literal (\'UUID()') is computed by the server, so its value
616 # is exactly as unknown here as a missing one.
617 my @pk_unknown = grep {
618 41 ▶ ! defined $to_insert->{$_} or is_literal_value($to_insert->{$_})
Condition66%2/3
!defined($to_insert->{$_}) || &is_literal_value($to_insert->{$_})
l!l&&r!l&&!r
30022
MC/DC50%1/2
!defined($to_insert->{$_}) || &is_literal_value($to_insert->{$_})
!defined($to_insert->{$_}) &is_literal_value($to_insert->{$_})
Truth table66%2/3
not(A) || B
A= !defined($to_insert->{$_})B= &is_literal_value($to_insert->{$_})
ABresult
1X1
011
000
619 } @pk;
620  
621 # LAST_INSERT_ID() carries one value, so the idiom needs a single-column
622 # AUTO_INCREMENT primary key.
623 my $autoinc_pk = (@pk == 1 and $col_infos->{$pk[0]}{is_auto_increment})
624 41 ▶ ? $pk[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@pk == 1 && $$col_infos{$pk[0]}{'is_auto_increment'} ? : 34 7 41
Condition66%2/3
@pk == 1 and $$col_infos{$pk[0]}{"is_auto_increment"}
!ll&&!rl&&r
7034
MC/DC50%1/2
@pk == 1 and $$col_infos{$pk[0]}{"is_auto_increment"}
@pk == 1 $$col_infos{$pk[0]}{"is_auto_increment"}
Truth table66%2/3
A and B
A= @pk == 1B= $$col_infos{$pk[0]}{"is_auto_increment"}
ABresult
0X0
100
111
625  
626 41 ▶ my $action = $on_conflict->{action} || 'update';
Condition50%1/2
$on_conflict->{'action'} || 'update'
l!l
410
MC/DC0%0/1
$on_conflict->{'action'} || 'update'
$on_conflict->{'action'}
Truth table50%1/2
A
A= $on_conflict->{'action'}
Aresult
11
00
627 41 ▶ my $set = $on_conflict->{set} || {};
Condition100%2/2
$on_conflict->{'set'} || {}
l!l
383
MC/DC100%1/1
$on_conflict->{'set'} || {}
$on_conflict->{'set'}
Truth table100%2/2
A
A= $on_conflict->{'set'}
Aresult
11
00
628  
629 41 my %extra;
630  
631 # The DO NOTHING emulation writes a column to itself; the primary key is
632 # the most harmless choice, the target the fallback.
633 41 ▶ if ($action eq 'nothing') {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "nothing") 3 38 41
634 3 ▶ my $noop = @pk ? $pk[0] : (@target_cols ? $target_cols[0] : undef);
Branch: 2 branches
BranchTrueFalseTotal
@pk ? : 3 0 3
@target_cols ? : 0 0 0
635 3 ▶ $extra{noop_column} = $noop if defined $noop;
Branch: 1 branch
BranchTrueFalseTotal
if defined $noop 3 0 3
636 }
637  
638 # result => 'void' / 'count' asks for one round-trip and nothing spent on
639 # naming the row, so no identity work is done and none is missing.
640 41 ▶ my $wants_identity = $opts->{no_retrieve} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'no_retrieve'} ? : 13 28 41
641  
642 # ADR 0036 section 4, rule 1: where the engine hands the written row back
643 # itself, none of the identity machinery below is needed -- no
644 # LAST_INSERT_ID(pk) no-op in the conflict set, no case distinction. That is
645 # MariaDB from 10.5 on (karr #29); MySQL has no RETURNING and never takes
646 # this branch.
647 #
648 # Core asks for RETURNING only for the columns it does not already have, so
649 # the rule is exactly "every primary key column is one of them". A key value
650 # the caller supplied comes back out of the caller's own data and is still no
651 # evidence of which row the statement touched -- with no conflict target in
652 # the grammar the collision may have happened on another unique index -- so
653 # the shapes below keep deciding those.
654 #
655 # Unless the caller says it does not read RETURNING: `returning => 0` in the
656 # options is the reader hint of a transport that always reads
657 # SELECT LAST_INSERT_ID() (the ev backend), so the idiom stays in.
658 my $reader_reads_last_insert_id =
659 41 ▶ defined $opts->{returning} && ! $opts->{returning};
Condition100%3/3
defined $opts->{'returning'} && !$opts->{'returning'}
!ll&&!rl&&r
3155
MC/DC100%2/2
defined $opts->{'returning'} && !$opts->{'returning'}
defined $opts->{'returning'} !$opts->{'returning'}
Truth table100%3/3
A && not(B)
A= defined $opts->{'returning'}B= !$opts->{'returning'}
ABresult
0X0
100
111
660  
661 41 ▶ my $returning_names_the_row =
Condition88%8/9
$self->_use_insert_returning && @pk && @pk_unknown == @pk && !$reader_reads_last_insert_id
!ll&&!rl&&r
27311
$self->_use_insert_returning and @pk and @pk_unknown == @pk
!ll&&!rl&&r
25214
$self->_use_insert_returning and @pk
!ll&&!rl&&r
25016
MC/DC75%3/4
$self->_use_insert_returning && @pk && @pk_unknown == @pk && !$reader_reads_last_insert_id
$self->_use_insert_returning @pk @pk_unknown == @pk !$reader_reads_last_insert_id
Truth table80%4/5
A and B and C && not(D)
A= $self->_use_insert_returningB= @pkC= @pk_unknown == @pkD= !$reader_reads_last_insert_id
ABCDresult
0XXX0
10XX0
110X0
11100
11111
662 $self->_use_insert_returning && @pk && @pk_unknown == @pk
663 && ! $reader_reads_last_insert_id;
664  
665 41 my ($nameable, $reason) = (0, undef);
666  
667 41 ▶ if (! $wants_identity) {
Branch: 5 branches
BranchTrueFalseTotal
if (not $wants_identity) { } 13 28 41
elsif (not @pk) { } 0 28 28
elsif ($returning_names_the_row) { } 8 20 28
elsif (defined $autoinc_pk and not defined $to_insert->{$autoinc_pk} and not exists $set->{$autoinc_pk}) { } 11 9 20
elsif (defined $effective_key and defined $pk_key and $effective_key eq $pk_key and not @pk_unknown) { } 2 7 9
668 13 $nameable = 1;
669 }
670 elsif (! @pk) {
671 # Nothing to name and nothing to withhold: core's own "no primary key
672 # came back" message says it exactly, so there is no MySQL detail to add.
673 0 $nameable = 0;
674 }
675 elsif ($returning_names_the_row) {
676 8 $nameable = 1;
677 }
678 ▶ elsif (
Condition83%5/6
defined $autoinc_pk and not defined $to_insert->{$autoinc_pk} and not exists $set->{$autoinc_pk}
!ll&&!rl&&r
9011
defined $autoinc_pk and not defined $to_insert->{$autoinc_pk}
!ll&&!rl&&r
5411
MC/DC66%2/3
defined $autoinc_pk and not defined $to_insert->{$autoinc_pk} and not exists $set->{$autoinc_pk}
defined $autoinc_pk not defined $to_insert->{$autoinc_pk} not exists $set->{$autoinc_pk}
Truth table75%3/4
A and not(B) and not(C)
A= defined $autoinc_pkB= not defined $to_insert->{$autoinc_pk}C= not exists $set->{$autoinc_pk}
ABCresult
0XX0
10X0
1100
1111
679 defined $autoinc_pk
680 and
681 # the value has to be generated by the engine -- an explicitly supplied
682 # one (literal included) leaves LAST_INSERT_ID() untouched on an insert
683 ! defined $to_insert->{$autoinc_pk}
684 and
685 ! exists $set->{$autoinc_pk}
686 ) {
687 # Case 1 -- the engine's own identity channel. A no-op on the stored
688 # value that makes LAST_INSERT_ID() report the primary key of the row
689 # that was actually touched, insert or update, no matter which unique
690 # index collided. Core then retrieves it exactly as it does for a plain
691 # autoinc insert.
692 #
693 # UNVERIFIED ASSUMPTION, the one place in this driver that depends on it
694 # (karr #27, ADR 0036): that this also holds when the UPDATE branch
695 # changes no value at all, which MySQL reports as 0 affected rows. If a
696 # live round-trip shows LAST_INSERT_ID() stale in that case, this branch
697 # -- and only this branch -- has to fall back to the unresolvable path.
698 11 $extra{identity_column} = $autoinc_pk;
699 11 $nameable = 1;
700 }
701 ▶ elsif (defined $effective_key and defined $pk_key
Condition66%6/9
defined $effective_key and defined $pk_key and $effective_key eq $pk_key and not @pk_unknown
!ll&&!rl&&r
702
defined $effective_key and defined $pk_key and $effective_key eq $pk_key
!ll&&!rl&&r
702
defined $effective_key and defined $pk_key
!ll&&!rl&&r
702
MC/DC25%1/4
defined $effective_key and defined $pk_key and $effective_key eq $pk_key and not @pk_unknown
defined $effective_key defined $pk_key $effective_key eq $pk_key not @pk_unknown
Truth table40%2/5
A and B and C and not(D)
A= defined $effective_keyB= defined $pk_keyC= $effective_key eq $pk_keyD= not @pk_unknown
ABCDresult
0XXX0
10XX0
110X0
11100
11111
702 and $effective_key eq $pk_key and ! @pk_unknown) {
703 # Case 2 -- the collision provably happened on the primary key, and the
704 # caller supplied its values, so the row is named without asking the
705 # server anything.
706 2 $nameable = 1;
707 }
708 else {
709 # Case 3 -- no channel. Which of the three shapes it is decides what the
710 # caller is told.
711 7 $nameable = 0;
712  
713 7 my $detail;
714 7 ▶ if (defined $autoinc_pk and exists $set->{$autoinc_pk}) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $autoinc_pk and exists $set->{$autoinc_pk}) { } 0 7 7
elsif (defined $autoinc_pk) { } 3 4 7
elsif (@pk_unknown) { } 0 4 4
Condition66%2/3
defined $autoinc_pk and exists $set->{$autoinc_pk}
!ll&&!rl&&r
430
MC/DC0%0/2
defined $autoinc_pk and exists $set->{$autoinc_pk}
defined $autoinc_pk exists $set->{$autoinc_pk}
Truth table66%2/3
A and B
A= defined $autoinc_pkB= exists $set->{$autoinc_pk}
ABresult
0X0
100
111
715 0 $detail = "the conflict set assigns the AUTO_INCREMENT primary key "
716 . "'$autoinc_pk' itself, which rules out the "
717 . 'LAST_INSERT_ID(pk) identity idiom';
718 }
719 elsif (defined $autoinc_pk) {
720 3 $detail = "the data supplies an explicit value for the AUTO_INCREMENT "
721 . "primary key '$autoinc_pk', so LAST_INSERT_ID() reports "
722 . 'nothing about the row on the insert branch';
723 }
724 elsif (@pk_unknown) {
725 0 $detail = 'the primary key (' . join(', ', @pk) . ') is not a single '
726 . 'AUTO_INCREMENT column and the data does not supply it '
727 . '(missing: ' . join(', ', @pk_unknown) . ')';
728 }
729 else {
730 $detail = 'the primary key (' . join(', ', @pk) . ') is not a single '
731 . 'AUTO_INCREMENT column, and with ' . scalar(keys %unique_cols)
732 . ' unique keys on the table ('
733 4 . join('; ', map { join(', ', @{ $unique_cols{$_} }) }
734 sort keys %unique_cols)
735 . ') a collision cannot be attributed to it';
736 }
737  
738 7 $reason = "upsert() on $sname cannot name the row it wrote, so no row is "
739 . 'returned: ON DUPLICATE KEY UPDATE does not report which key '
740 . "collided, and $detail. Pass result => 'count' or 'void' if the "
741 . 'written row is not needed, or upsert against a table whose only '
742 . 'unique key is the conflict target.';
743 }
744  
745 return {
746 41 nameable => $nameable,
747 wants_identity => $wants_identity,
748 primary_columns => \@pk,
749 extra => \%extra,
750 reason => $reason
751 };
752 }
753  
754 # Order-insensitive identity of a column set, so "the same unique index" is
755 # one comparison rather than a nested loop.
756 256 ▶sub _mysql_colset_key { join "\0", sort @_ }
Subroutine _mysql_colset_key: called CC=1 SCAR=0.0
757  
758 4 ▶sub sqlt_type {
Subroutine sqlt_type: called CC=1 SCAR=0.0
Pod documented
759 4 return 'MySQL';
760 }
761  
762  
763 0 ▶sub deploy_defaults {
Subroutine deploy_defaults: not called CC=1 SCAR=6.9
Pod documented
764 0 return (add_drop_table => 1);
765 }
766  
767  
768 0 ▶sub deploy_setup {
Subroutine deploy_setup: not called CC=1 SCAR=6.9
Pod documented
769 0 my ($self, $schema) = @_;
770 0 eval { $self->connect_call_set_zero_date_permissive };
771 }
772  
773 0 ▶sub connect_call_set_zero_date_permissive {
Subroutine connect_call_set_zero_date_permissive: not called CC=1 SCAR=6.9
Pod documented
774 0 my $self = shift;
775 0 $self->_do_query(
776 q{SET SESSION sql_mode = REPLACE(REPLACE(@@SESSION.sql_mode,'NO_ZERO_DATE',''),'NO_ZERO_IN_DATE','')}
777 );
778 }
779  
780  
781  
782 0 ▶sub _mask_error_values {
Subroutine _mask_error_values: not called CC=5 SCAR=34.0
783 0 my ($self, $text, $values, $statement) = @_;
784  
785 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
786  
787 # DBI sets the error of the handle before it calls the error handler, so the
788 # code of the error that is being reported is the one of the connection. The
789 # server words its text in the language of the session; the code is the same
790 # in every one.
791 0 ▶ my $code = eval { my $dbh = $self->_dbh; $dbh && $dbh->err };
Condition0%0/3
$dbh && $dbh->err
!ll&&!rl&&r
000
MC/DC0%0/2
$dbh && $dbh->err
$dbh $dbh->err
Truth table0%0/3
A && B
A= $dbhB= $dbh->err
ABresult
0X0
100
111
792  
793 0 my $masked = eval { DBIO::MySQL::Util::mask_error_details($text, $values, $statement, $code) };
794 0 ▶ $text = $masked if defined $masked;
Branch: 1 branch
BranchTrueFalseTotal
if defined $masked 0 0 0
795  
796 0 return $self->next::method($text, $values, $statement);
797 }
798  
799 # karr #33 -- the function DBIO::ResultSet::rand drops into an order_by
800 # literal. Core answers RANDOM(), which neither product has; both spell it
801 # RAND(). The spelling is the easy half. The half that has to be CHECKED is
802 # whether the engine evaluates it per row, because a function that is computed
803 # once hands every row the same sort key and ORDER BY <it> is then a silent
804 # non-shuffle (that is what Sybase ASE's rand() does -- dbio-sybase karr #28).
805 # Both products document per-row evaluation, and neither leaves it to
806 # inference: MySQL's manual endorses ORDER BY RAND() as the way "to retrieve
807 # rows in random order" and its RAND() entry shows SELECT i, RAND() FROM t
808 # returning a different value for each of three rows, while MariaDB's RAND()
809 # page says outright that ORDER BY RAND() makes the server "generate a random
810 # value for each of them". See the "Random ordering" POD section.
811 #
812 # On the class both DBDs and both products share, because it is an engine fact
813 # that holds for both of them (karr k28, this dist's ADR 0001).
814 3 ▶sub _random_function { 'RAND()' }
Subroutine _random_function: called CC=1 SCAR=0.0
815  
816 40 ▶sub _bind_host_into_dsn {
Subroutine _bind_host_into_dsn: called CC=15 SCAR=27.1
817 40 my ($self, $driver, $dsn, $host, $port) = @_;
818  
819 40 ▶ return $self->next::method($driver, $dsn, $host, $port)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dsn and $dsn =~ /^(dbi:\w*(?:\([^)]*\))?:)(.*)\z/is 1 39 40
Condition66%2/3
defined $dsn and $dsn =~ /^(dbi:\w*(?:\([^)]*\))?:)(.*)\z/is
!ll&&!rl&&r
0139
MC/DC50%1/2
defined $dsn and $dsn =~ /^(dbi:\w*(?:\([^)]*\))?:)(.*)\z/is
defined $dsn $dsn =~ /^(dbi:\w*(?:\([^)]*\))?:)(.*)\z/is
Truth table66%2/3
A and B
A= defined $dsnB= $dsn =~ /^(dbi:\w*(?:\([^)]*\))?:)(.*)\z/is
ABresult
0X0
100
111
820 unless defined $dsn and $dsn =~ /^(dbi:\w*(?:\([^)]*\))?:)(.*)\z/is;
821 39 my ($prefix, $rest) = ($1, $2);
822  
823 39 for my $part (grep { length } split /;/, $rest) {
824 75 ▶ return (undef, "the key '$1' naming the server by a socket")
Branch: 1 branch
BranchTrueFalseTotal
if $part =~ /^((?:mysql|mariadb)_socket)=/i 4 71 75
825 if $part =~ /^((?:mysql|mariadb)_socket)=/i;
826 }
827  
828 # key=value parts: the core form, host= and port= tokens.
829 35 ▶ if ($rest =~ /=/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /=/) 17 18 35
830 return (undef, 'a positional part beside key=value parts')
831 17 ▶ if grep { length and !/^\w+=/ } split /;/, $rest;
Branch: 1 branch
BranchTrueFalseTotal
if grep {length $_ and not /^\w+=/;} split(/;/, $rest, 0) 2 15 17
Condition66%2/3
length $_ && !/^\w+=/
!ll&&!rl&&r
0462
MC/DC50%1/2
length $_ && !/^\w+=/
length $_ !/^\w+=/
Truth table66%2/3
A && not(B)
A= length $_B= !/^\w+=/
ABresult
0X0
100
111
832 15 return $self->next::method($driver, $dsn, $host, $port);
833 }
834  
835 18 ▶ return $self->next::method($driver, $dsn, $host, $port) unless length $rest;
Branch: 1 branch
BranchTrueFalseTotal
unless length $rest 1 17 18
836 17 ▶ return (undef, 'a positional part beside a semicolon') if $rest =~ /;/;
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /;/ 1 16 17
837  
838 # database[:host[:port]], read the way both DBDs read it.
839 16 my @part;
840 16 my $left = $rest;
841 16 ▶ while (length $left) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $left) 41 16 57
842 41 my $val;
843 41 ▶ if ($left =~ /([^:;]*\[.*]|[^:;]*)[:;](.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left =~ /([^:;]*\[.*]|[^:;]*)[:;](.*)/) { } 25 16 41
844 25 ($val, $left) = ($1, $2);
845 }
846 else {
847 16 ($val, $left) = ($left, '');
848 }
849 41 push @part, $val;
850 }
851 16 ▶ return (undef, 'a positional DSN with more than database, host and port')
Branch: 1 branch
BranchTrueFalseTotal
if @part > 3 1 15 16
852 if @part > 3;
853  
854 15 ▶ $host = "[$host]" if $host =~ /:/;
Branch: 1 branch
BranchTrueFalseTotal
if $host =~ /:/ 1 14 15
855 15 ▶ $port = $part[2] unless defined $port;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $port 2 13 15
856 15 return $prefix . join ':', $part[0], $host, grep { defined } $port;
857 }
858  
859  
860 14 ▶sub _ddl_sql_dialect { 'mysql' }
Subroutine _ddl_sql_dialect: called CC=1 SCAR=0.0
861  
862  
863 # _explain_query is deliberately NOT overridden, and the non-override is the
864 # decision rather than an omission -- so it is recorded where the override used
865 # to sit. Core's base operation is
866 #
867 # my (undef, $sth) = $self->_execute_rendered("EXPLAIN $sql", $bind);
868 # return $sth->fetchall_arrayref;
869 #
870 # which is exactly right for both products: EXPLAIN <SELECT> is the plan
871 # statement on each, it does not execute the query, and each answers with a
872 # tabular rowset that fetchall_arrayref collects. See the "Query plans" POD
873 # section for the citations.
874 #
875 # What used to sit here was
876 #
877 # sub _explain_sql { "EXPLAIN $_[1]" }
878 #
879 # and it was already DEAD when it was removed: core ADR 0040 / karr #138 took
880 # the _explain_sql string hook out -- not deprecated, not aliased -- and put
881 # _explain_query in its slot in DBIO 0.900004.
882 # Core had stopped calling it, so it produced the same statement by inheritance
883 # while looking like the thing that produced it. It also said nothing: it was
884 # byte-for-byte core's own default even while the hook still existed.
885  
886 0 ▶sub _exec_svp_begin {
Subroutine _exec_svp_begin: not called CC=1 SCAR=6.9
887 0 my ($self, $name) = @_;
888  
889 0 $self->_dbh->do("SAVEPOINT $name");
890 }
891  
892 0 ▶sub _exec_svp_release {
Subroutine _exec_svp_release: not called CC=1 SCAR=6.9
893 0 my ($self, $name) = @_;
894  
895 0 $self->_dbh->do("RELEASE SAVEPOINT $name");
896 }
897  
898 0 ▶sub _exec_svp_rollback {
Subroutine _exec_svp_rollback: not called CC=1 SCAR=6.9
899 0 my ($self, $name) = @_;
900  
901 0 $self->_dbh->do("ROLLBACK TO SAVEPOINT $name")
902 }
903  
904 6 ▶sub is_replicating {
Subroutine is_replicating: called CC=7 SCAR=21.0
Pod documented
905 6 ▶ my $status = shift->_replication_status_row
Branch: 1 branch
BranchTrueFalseTotal
my $status = (shift())->_replication_status_row or return 4 2 6
906 or return;
907  
908 # Both column spellings, because the row's is decided by the statement the
909 # server answered -- see _replication_status_statement.
910 4 ▶ my $io = $status->{Replica_IO_Running} // $status->{Slave_IO_Running};
Condition66%2/3
$status->{"Replica_IO_Running"} // $status->{"Slave_IO_Running"}
l!l&&r!l&&!r
220
MC/DC0%0/2
$status->{"Replica_IO_Running"} // $status->{"Slave_IO_Running"}
$status->{"Replica_IO_Running"} $status->{"Slave_IO_Running"}
Truth table66%2/3
A // B
A= $status->{"Replica_IO_Running"}B= $status->{"Slave_IO_Running"}
ABresult
1X1
011
000
911 4 ▶ my $sql = $status->{Replica_SQL_Running} // $status->{Slave_SQL_Running};
Condition66%2/3
$status->{"Replica_SQL_Running"} // $status->{"Slave_SQL_Running"}
l!l&&r!l&&!r
220
MC/DC0%0/2
$status->{"Replica_SQL_Running"} // $status->{"Slave_SQL_Running"}
$status->{"Replica_SQL_Running"} $status->{"Slave_SQL_Running"}
Truth table66%2/3
A // B
A= $status->{"Replica_SQL_Running"}B= $status->{"Slave_SQL_Running"}
ABresult
1X1
011
000
912  
913 # A status row whose thread columns we cannot find is not "not
914 # replicating", it is "this driver did not understand the answer" -- which
915 # is what core's undef means (DBIO::Replicated::Pool prints "does not
916 # support is_replicating" and leaves the replicant to manual management).
917 4 ▶ return undef unless defined $io and defined $sql;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $io and defined $sql 0 4 4
Condition33%1/3
defined $io and defined $sql
!ll&&!rl&&r
004
MC/DC0%0/2
defined $io and defined $sql
defined $io defined $sql
Truth table33%1/3
A and B
A= defined $ioB= defined $sql
ABresult
0X0
100
111
918  
919 4 ▶ return ($io eq 'Yes') && ($sql eq 'Yes');
Condition66%2/3
$io eq 'Yes' && $sql eq 'Yes'
!ll&&!rl&&r
103
MC/DC50%1/2
$io eq 'Yes' && $sql eq 'Yes'
$io eq 'Yes' $sql eq 'Yes'
Truth table66%2/3
A && B
A= $io eq 'Yes'B= $sql eq 'Yes'
ABresult
0X0
100
111
920 }
921  
922  
923 4 ▶sub lag_behind_master {
Subroutine lag_behind_master: called CC=3 SCAR=11.1
Pod documented
924 4 ▶ my $status = shift->_replication_status_row
Branch: 1 branch
BranchTrueFalseTotal
my $status = (shift())->_replication_status_row or return undef 3 1 4
925 or return undef;
926  
927 3 ▶ return $status->{Seconds_Behind_Source} // $status->{Seconds_Behind_Master};
Condition66%2/3
$status->{"Seconds_Behind_Source"} // $status->{"Seconds_Behind_Master"}
l!l&&r!l&&!r
120
MC/DC0%0/2
$status->{"Seconds_Behind_Source"} // $status->{"Seconds_Behind_Master"}
$status->{"Seconds_Behind_Source"} $status->{"Seconds_Behind_Master"}
Truth table66%2/3
A // B
A= $status->{"Seconds_Behind_Source"}B= $status->{"Seconds_Behind_Master"}
ABresult
1X1
011
000
928 }
929  
930  
931 26 ▶sub _replication_status_statement {
Subroutine _replication_status_statement: called CC=5 SCAR=16.1
932 26 my $self = shift;
933  
934 26 ▶ my $ver = $self->_server_info->{normalized_dbms_version} // 0;
Condition50%1/2
$self->_server_info->{"normalized_dbms_version"} // 0
l!l
260
MC/DC0%0/1
$self->_server_info->{"normalized_dbms_version"} // 0
$self->_server_info->{"normalized_dbms_version"}
Truth table50%1/2
A
A= $self->_server_info->{"normalized_dbms_version"}
Aresult
11
00
935  
936 26 ▶ return ( $ver >= 10.005001 ) ? 'SHOW REPLICA STATUS' : 'SHOW SLAVE STATUS'
Branch: 2 branches
BranchTrueFalseTotal
if $self->_is_mariadb 10 16 26
$ver >= 10.005001 ? : 6 4 10
937 if $self->_is_mariadb;
938  
939 # An unreadable version is the one case with a real choice to make, and it
940 # goes to the legacy spelling: that is wrong only on MySQL 8.4 and up,
941 # where the version is hardly ever unreadable, while the modern spelling
942 # would be wrong on every MySQL below 8.0.22.
943 16 ▶ return ( $ver >= 8.000022 ) ? 'SHOW REPLICA STATUS' : 'SHOW SLAVE STATUS';
Branch: 1 branch
BranchTrueFalseTotal
$ver >= 8.000022 ? : 10 6 16
944 }
945  
946  
947 10 ▶sub _replication_status_row {
Subroutine _replication_status_row: called CC=1 SCAR=0.0
948 10 my $self = shift;
949 10 return $self->_get_dbh->selectrow_hashref($self->_replication_status_statement);
950 }
951  
952  
953 50 1;
954  
955 __END__
« blib/lib/DBIO/MySQL/Diff.pm ↑ Summary blib/lib/DBIO/MySQL/Deploy.pm »