| 1 | package DBIO::MySQL::SQLMaker; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: MySQL-specific SQL generation for DBIO | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 38 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 38 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 38 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 38 | ▶ | use base qw( DBIO::SQLMaker ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 38 | ▶ | use Text::Balanced (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 38 | ▶ | use DBIO::Util qw( is_literal_value ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 99 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 99 | my $self = shift->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | # copy first: the table of render ops may be shared with other makers | ||||||||||||||||||||||||||||||||||||||||||
| 19 | $self->{render_op} = { | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 99 | %{ $self->{render_op} }, | |||||||||||||||||||||||||||||||||||||||||
| 21 | nulls_first => '_render_op_nulls', | ||||||||||||||||||||||||||||||||||||||||||
| 22 | nulls_last => '_render_op_nulls', | ||||||||||||||||||||||||||||||||||||||||||
| 23 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 99 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 12 | ▶ | sub _render_op_nulls { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_render_op_nulls: called CC=5 SCAR=17.5
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 12 | my ($self, $op, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 12 | my ($node) = @$args; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 12 | my $expr = $node; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 12 | ▶ | if (ref $node eq 'HASH' and ref $node->{-op} eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $node eq "HASH" and ref $node->{"-op"} eq "ARRAY" and $node->{"-op"}[0] =~ /\A(?:asc|desc)\z/
ref $node eq "HASH" and ref $node->{"-op"} eq "ARRAY"
MC/DC0%0/3
ref $node eq "HASH" and ref $node->{"-op"} eq "ARRAY" and $node->{"-op"}[0] =~ /\A(?:asc|desc)\z/
ref $node eq "HASH"
ref $node->{"-op"} eq "ARRAY"
$node->{"-op"}[0] =~ /\A(?:asc|desc)\z/
Truth table25%1/4
A and B and C
A= ref $node eq "HASH"B= ref $node->{"-op"} eq "ARRAY"C= $node->{"-op"}[0] =~ /\A(?:asc|desc)\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | and $node->{-op}[0] =~ /\A(?:asc|desc)\z/) { | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 12 | $expr = $node->{-op}[1]; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 12 | ▶ | return $self->join_query_parts(', ', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | { -op => [ ( $op eq 'nulls_first' ? 'desc' : 'asc' ), | ||||||||||||||||||||||||||||||||||||||||||
| 41 | { -op => [ 'is_null', $expr ] } ] }, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | $node, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | sub apply_limit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply_limit: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | my ( $self, $sql, $rs_attrs, $rows, $offset ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | $sql .= $self->_parse_rs_attrs( $rs_attrs ) . " LIMIT "; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | ▶ | if ($offset) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | $sql .= '?, '; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | push @{$self->{limit_bind}}, [ $self->__offset_bindtype => $offset ]; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | $sql .= '?'; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | push @{$self->{limit_bind}}, [ $self->__rows_bindtype => $rows ]; | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | return $sql; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | # | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # MySQL does not understand the standard INSERT INTO $table DEFAULT VALUES | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # Adjust SQL here instead | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 99 | ▶ | sub insert { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 99 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 99 | my ($table, $data, $options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 99 | my $have_options = ref $options eq 'HASH'; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | # ADR 0036: $options->{on_conflict} is the atomic-upsert transport, and | ||||||||||||||||||||||||||||||||||||||||||
| 71 | # consuming (deleting) it is part of the contract -- the generic | ||||||||||||||||||||||||||||||||||||||||||
| 72 | # DBIO::SQLMaker::ClassicExtensions::insert throws when it still sees the | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # key, because a clause it cannot place must never be silently dropped | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # from the statement. | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 99 | ▶ | my $on_conflict = $have_options ? delete $options->{on_conflict} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | # RETURNING is held back over the call to the base for the same reason: it | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # is the LAST tail of the statement, and the conflict clause goes before it | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # (ADR 0036 section 2, trap 1). So the statement is assembled here in | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # grammar order rather than appended to whatever the base produced. | ||||||||||||||||||||||||||||||||||||||||||
| 81 | # MariaDB 10.5+ is the only server in this driver's reach that has | ||||||||||||||||||||||||||||||||||||||||||
| 82 | # RETURNING at all (see DBIO::MySQL::Storage/_determine_supports_insert_returning). | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 99 | ▶ | my $returning = $have_options ? delete $options->{returning} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 99 | my ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||
| 86 | 99 | ▶ | if (! $data or (ref $data eq 'HASH' and ! keys %$data) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $data or ref $data eq "HASH" and not keys %$data
ref $data eq "HASH" and not keys %$data
MC/DC33%1/3
not $data or ref $data eq "HASH" and not keys %$data
not $data
ref $data eq "HASH"
not keys %$data
Truth table50%2/4
not(A) or B and not(C)
A= not $dataB= ref $data eq "HASH"C= not keys %$data
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | $sql = 'INSERT INTO ' . $self->_quote($table) . ' () VALUES ()'; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 98 | ($sql, @bind) = $self->next::method($table, $data, $options); | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | # Put it back before anything else can happen: DBIO::Storage::DBI::insert | ||||||||||||||||||||||||||||||||||||||||||
| 94 | # reads $options->{returning} AGAIN after _execute, to decide whether to | ||||||||||||||||||||||||||||||||||||||||||
| 95 | # fetch the returned row off the statement handle. A key that stays deleted | ||||||||||||||||||||||||||||||||||||||||||
| 96 | # yields perfectly correct SQL whose result is never collected -- and it | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # looks like an identity problem rather than a plumbing one (ADR 0036 | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # section 2, trap 2). | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 98 | ▶ | $options->{returning} = $returning if defined $returning; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 98 | ▶ | if ($on_conflict) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 39 | my ($tail, @tail_bind) = $self->_insert_on_conflict($on_conflict, $data); | |||||||||||||||||||||||||||||||||||||||||
| 103 | 38 | $sql .= $tail; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 38 | push @bind, @tail_bind; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 97 | ▶ | if (defined $returning) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 6 | my ($tail, @tail_bind) = $self->_insert_returning($options); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 6 | $sql .= $tail; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 6 | push @bind, @tail_bind; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 97 | return ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 39 | ▶ | sub _insert_row_alias { $_[0]->{_upsert_row_alias} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_insert_row_alias: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 39 | ▶ | sub _insert_on_conflict { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_insert_on_conflict: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 39 | my ($self, $on_conflict, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 39 | ▶ | my $action = $on_conflict->{action} || 'update'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$on_conflict->{'action'} || 'update'
MC/DC0%0/1
$on_conflict->{'action'} || 'update'
$on_conflict->{'action'}
Truth table50%1/2
A
A= $on_conflict->{'action'}
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 39 | my $identity = $on_conflict->{identity_column}; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 39 | my $alias = $self->_insert_row_alias; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 39 | my (@assignments, @bind, $alias_used); | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | # LAST_INSERT_ID(<pk>) is a no-op on the stored value; its only purpose is | ||||||||||||||||||||||||||||||||||||||||||
| 131 | # to make LAST_INSERT_ID() report the primary key of the row the statement | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # actually touched -- insert or update, regardless of which unique index | ||||||||||||||||||||||||||||||||||||||||||
| 133 | # collided (ADR 0036 section 4, rule 3). | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 39 | ▶ | my $identity_assignment = defined $identity | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | ? $self->_quote($identity) . ' = LAST_INSERT_ID(' . $self->_quote($identity) . ')' | ||||||||||||||||||||||||||||||||||||||||||
| 136 | : undef; | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 39 | ▶ | if ($action eq 'nothing') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 5 | ▶ | if (defined $identity_assignment) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | # the no-op set and the identity channel are the same assignment here | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | push @assignments, $identity_assignment; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 144 | my $col = $on_conflict->{noop_column} | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 4 | ▶ | // $self->_insert_on_conflict_noop_column($on_conflict, $data); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$on_conflict->{"noop_column"} // $self->_insert_on_conflict_noop_column($on_conflict, $data)
MC/DC0%0/2
$on_conflict->{"noop_column"} // $self->_insert_on_conflict_noop_column($on_conflict, $data)
$on_conflict->{"noop_column"}
$self->_insert_on_conflict_noop_column($on_conflict, $data)
Truth table66%2/3
A // B
A= $on_conflict->{"noop_column"}B= $self->_insert_on_conflict_noop_column($on_conflict, $data)
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 4 | ▶ | $self->throw_exception( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | "Cannot emulate ON CONFLICT DO NOTHING on MySQL: there is no column " | ||||||||||||||||||||||||||||||||||||||||||
| 149 | . 'to assign to itself. ON DUPLICATE KEY UPDATE requires at least one ' | ||||||||||||||||||||||||||||||||||||||||||
| 150 | . 'assignment.' | ||||||||||||||||||||||||||||||||||||||||||
| 151 | ) unless defined $col; | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 4 | push @assignments, $self->_quote($col) . ' = ' . $self->_quote($col); | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 34 | ▶ | my $set = $on_conflict->{set} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$on_conflict->{'set'} || {}
MC/DC0%0/1
$on_conflict->{'set'} || {}
$on_conflict->{'set'}
Truth table50%1/2
A
A= $on_conflict->{'set'}
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 34 | for my $col (sort keys %$set) { | |||||||||||||||||||||||||||||||||||||||||
| 160 | my ($expr, $used_alias, @expr_bind) | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 37 | = $self->_insert_on_conflict_value($col, $set->{$col}, $alias); | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 37 | push @assignments, $self->_quote($col) . ' = ' . $expr; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 37 | push @bind, @expr_bind; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 37 | ▶ | $alias_used ||= $used_alias; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$alias_used ||= $used_alias
MC/DC100%2/2
$alias_used ||= $used_alias
$alias_used
$used_alias
Truth table100%3/3
A ||= B
A= $alias_usedB= $used_alias
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 34 | ▶ | push @assignments, $identity_assignment if defined $identity_assignment; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 39 | ▶ | $self->throw_exception( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 'ON DUPLICATE KEY UPDATE requires at least one assignment, but the ' | ||||||||||||||||||||||||||||||||||||||||||
| 173 | . 'conflict set is empty' | ||||||||||||||||||||||||||||||||||||||||||
| 174 | ) unless @assignments; | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 38 | my $tail = ''; | |||||||||||||||||||||||||||||||||||||||||
| 177 | # the row alias is introduced in the statement itself, right after the | ||||||||||||||||||||||||||||||||||||||||||
| 178 | # VALUES clause; L</insert> appends this whole tail before RETURNING, which | ||||||||||||||||||||||||||||||||||||||||||
| 179 | # is where the two would otherwise collide (they never do in practice -- | ||||||||||||||||||||||||||||||||||||||||||
| 180 | # the alias is MySQL 8.0.20+, RETURNING is MariaDB, no server has both) | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 38 | ▶ | $tail .= ' AS ' . $self->_quote($alias) if $alias_used; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 38 | $tail .= ' ON DUPLICATE KEY UPDATE ' . join(', ', @assignments); | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 38 | return ($tail, @bind); | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | # One conflict-set assignment. Returns the right-hand side, whether it used | ||||||||||||||||||||||||||||||||||||||||||
| 188 | # the row alias, and any binds it needs. | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 37 | ▶ | sub _insert_on_conflict_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_insert_on_conflict_value: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 37 | my ($self, $col, $value, $alias) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 37 | ▶ | if (ref $value eq 'HASH' and keys %$value == 1 and exists $value->{-attempted}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $value eq "HASH" and keys %$value == 1 and exists $value->{"-attempted"}
ref $value eq "HASH" and keys %$value == 1
MC/DC33%1/3
ref $value eq "HASH" and keys %$value == 1 and exists $value->{"-attempted"}
ref $value eq "HASH"
keys %$value == 1
exists $value->{"-attempted"}
Truth table50%2/4
A and B and C
A= ref $value eq "HASH"B= keys %$value == 1C= exists $value->{"-attempted"}
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 34 | my $attempted = $value->{-attempted}; | |||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 34 | ▶ | return ($self->_quote($alias) . '.' . $self->_quote($attempted), 1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | if defined $alias; | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 30 | return ('VALUES(' . $self->_quote($attempted) . ')', 0); | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 3 | ▶ | if (my $literal = is_literal_value($value)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | my ($sql, @literal_bind) = @$literal; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 2 | return ($sql, 0, @literal_bind); | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | return ('?', 0, $self->_bindtype($col, $value)); | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | # The column the DO NOTHING emulation assigns to itself when the storage did | ||||||||||||||||||||||||||||||||||||||||||
| 210 | # not name one (a maker driven directly, without a ResultSource behind it). | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 1 | ▶ | sub _insert_on_conflict_noop_column { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_insert_on_conflict_noop_column: called CC=5 SCAR=25.2
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | my ($self, $on_conflict, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 1 | my $target = $on_conflict->{target}; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 1 | ▶ | return $target->[0] if ref $target eq 'ARRAY' and @$target; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $target eq "ARRAY" and @$target
MC/DC0%0/2
ref $target eq "ARRAY" and @$target
ref $target eq "ARRAY"
@$target
Truth table33%1/3
A and B
A= ref $target eq "ARRAY"B= @$target
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | return (sort keys %$data)[0] if ref $data eq 'HASH' and keys %$data; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $data eq "HASH" and keys %$data
MC/DC0%0/2
ref $data eq "HASH" and keys %$data
ref $data eq "HASH"
keys %$data
Truth table0%0/3
A and B
A= ref $data eq "HASH"B= keys %$data
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | # Allow STRAIGHT_JOIN's | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 12 | ▶ | sub _generate_join_clause { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_join_clause: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 12 | my ($self, $join_type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 12 | ▶ | if( $join_type && $join_type =~ /^STRAIGHT\z/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$join_type and $join_type =~ /^STRAIGHT\z/i
MC/DC100%2/2
$join_type and $join_type =~ /^STRAIGHT\z/i
$join_type
$join_type =~ /^STRAIGHT\z/i
Truth table100%3/3
A and B
A= $join_typeB= $join_type =~ /^STRAIGHT\z/i
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 2 | return ' STRAIGHT_JOIN ' | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 10 | return $self->next::method($join_type); | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 6 | ▶ | sub _wrap_self_referencing_subquery { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wrap_self_referencing_subquery: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 6 | my ($self, $sql, $target_name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 6 | ▶ | return $sql unless $target_name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 6 | my $re = qr/ (?<!DELETE) [\s\)] (?: FROM | JOIN ) \s (?: \` \Q$target_name\E \` | \Q$target_name\E ) [\s\(] /xi; | |||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 6 | ▶ | return $sql unless $sql =~ $re; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 5 | my $new_sql; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 5 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 11 | my ($prefix, $parenthesized); | |||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 11 | ($parenthesized, $sql, $prefix) = do { | |||||||||||||||||||||||||||||||||||||||||
| 248 | # idiotic design - writes to $@ but *DOES NOT* throw exceptions | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 11 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 250 | 11 | Text::Balanced::extract_bracketed( $sql, '()', qr/[^\(]*/ ); | |||||||||||||||||||||||||||||||||||||||||
| 251 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | # this is how an error is indicated, in addition to crapping in $@ | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 11 | ▶ | last unless $parenthesized; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 6 | ▶ | if ($parenthesized =~ $re) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | # is this a select subquery? | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 6 | ▶ | if ( $parenthesized =~ /^ \( \s* SELECT \s+ /xi ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 5 | $parenthesized = "( SELECT * FROM $parenthesized `_forced_double_subquery` )"; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | # then drill down until we find it (if at all) | ||||||||||||||||||||||||||||||||||||||||||
| 262 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | $parenthesized =~ s/^ \( (.+) \) $/$1/x; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | $parenthesized = join ' ', '(', $self->_wrap_self_referencing_subquery( $parenthesized, $target_name ), ')'; | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 6 | $new_sql .= $prefix . $parenthesized; | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 5 | return $new_sql . $sql; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 3 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 3 | my ($target, $source, $attributes) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 3 | my ($sql, @bind) = $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | # Extract target table name for self-referencing detection | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 3 | my $target_name = $self->_extract_target_name($target); | |||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 3 | ▶ | $sql = $self->_wrap_self_referencing_subquery($sql, $target_name) if $target_name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 3 | return ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 2 | ▶ | sub delete { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 2 | my ($target, $source, $attributes) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 2 | my ($sql, @bind) = $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | # Extract target table name for self-referencing detection | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 2 | my $target_name = $self->_extract_target_name($target); | |||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 2 | ▶ | $sql = $self->_wrap_self_referencing_subquery($sql, $target_name) if $target_name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 2 | return ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 5 | ▶ | sub _extract_target_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_target_name: called CC=6 SCAR=19.3
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 5 | my ($self, $target) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 5 | ▶ | return unless defined $target; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 5 | ▶ | if (ref $target eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 2 | ▶ | if ($$target =~ /^ (?: | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | \` ( [^`]+ ) \` #` | ||||||||||||||||||||||||||||||||||||||||||
| 310 | | ( [\w\-]+ ) | ||||||||||||||||||||||||||||||||||||||||||
| 311 | ) $/x | ||||||||||||||||||||||||||||||||||||||||||
| 312 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 2 | ▶ | return (defined $1) ? $1 : $2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | return; # complex scalar ref, can't deal | |||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | # For HASH refs (simple result source) or plain strings, return as-is | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 3 | ▶ | return ref $target ? undef : $target; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | # | ||||||||||||||||||||||||||||||||||||||||||
| 324 | # Support for MySQL lock clause syntax according to specification | ||||||||||||||||||||||||||||||||||||||||||
| 325 | # including updates introduced in MySQL 8.0.1) | ||||||||||||||||||||||||||||||||||||||||||
| 326 | # FOR UPDATE | FOR SHARE [OF tbl_name [, tbl_name] ...] [NOWAIT | SKIP LOCKED] | ||||||||||||||||||||||||||||||||||||||||||
| 327 | # | ||||||||||||||||||||||||||||||||||||||||||
| 328 | # Which of those three parts the server at the other end actually has is a | ||||||||||||||||||||||||||||||||||||||||||
| 329 | # SERVER question, not a DBD one, so the storage answers it and stashes the | ||||||||||||||||||||||||||||||||||||||||||
| 330 | # answer here (karr #30, same shape as _insert_row_alias above). See | ||||||||||||||||||||||||||||||||||||||||||
| 331 | # DBIO::MySQL::Storage/_lock_dialect for the version table. | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 38 | my $lock_modifiers = { | |||||||||||||||||||||||||||||||||||||||||
| 334 | nowait => 'NOWAIT', | ||||||||||||||||||||||||||||||||||||||||||
| 335 | skip_locked => 'SKIP LOCKED' | ||||||||||||||||||||||||||||||||||||||||||
| 336 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | # What a maker driven without a storage assumes: a current MySQL. Same polarity | ||||||||||||||||||||||||||||||||||||||||||
| 339 | # as the set-operation declarations in DBIO::MySQL::Storage -- every non-EOL | ||||||||||||||||||||||||||||||||||||||||||
| 340 | # MySQL is past 8.0.1, so the permissive answer is right for essentially the | ||||||||||||||||||||||||||||||||||||||||||
| 341 | # whole installed base, and the two servers that need the older spelling | ||||||||||||||||||||||||||||||||||||||||||
| 342 | # (MariaDB, MySQL before 8.0.1) are exactly the ones a connected storage can | ||||||||||||||||||||||||||||||||||||||||||
| 343 | # recognise. Byte-for-byte the behaviour this maker had before karr #30. | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 38 | my $DEFAULT_LOCK_DIALECT = { | |||||||||||||||||||||||||||||||||||||||||
| 345 | share => 'FOR SHARE', | ||||||||||||||||||||||||||||||||||||||||||
| 346 | of => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 347 | nowait => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 348 | skip_locked => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 349 | server => 'a MySQL 8.0.1 or newer (assumed -- no server was asked)', | ||||||||||||||||||||||||||||||||||||||||||
| 350 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 38 | ▶ | sub _lock_dialect { $_[0]->{_lock_dialect} || $DEFAULT_LOCK_DIALECT } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lock_dialect: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 38 | ▶ | sub _lock_select { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lock_select: called CC=11 SCAR=24.2
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 38 | my ($self, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | 38 | my $dialect = $self->_lock_dialect; | |||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | my $lock_types = { | ||||||||||||||||||||||||||||||||||||||||||
| 360 | update => 'FOR UPDATE', | ||||||||||||||||||||||||||||||||||||||||||
| 361 | share => $dialect->{share}, | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 38 | }; | |||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | # Handle hash-based configuration to support new featureset | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 38 | ▶ | if (ref $type eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 30 | my $lock_type = $type->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 30 | my $tables = $type->{of}; | |||||||||||||||||||||||||||||||||||||||||
| 368 | 30 | my $modifier = $type->{modifier}; | |||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 30 | ▶ | my $lock_clause = $lock_types->{$lock_type} | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$lock_types->{$lock_type} || $self->throw_exception("Unknown SELECT .. FOR type '${lock_type}' requested")
MC/DC0%0/2
$lock_types->{$lock_type} || $self->throw_exception("Unknown SELECT .. FOR type '${lock_type}' requested")
$lock_types->{$lock_type}
$self->throw_exception("Unknown SELECT .. FOR type '${lock_type}' requested")
Truth table33%1/3
A || B
A= $lock_types->{$lock_type}B= $self->throw_exception("Unknown SELECT .. FOR type '${lock_type}' requested")
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | || $self->throw_exception("Unknown SELECT .. FOR type '$lock_type' requested"); | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | # Add OF clause if tables are specified | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 30 | ▶ | if ($tables) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | $self->throw_exception( | ||||||||||||||||||||||||||||||||||||||||||
| 376 | "This server has no OF clause on a locking read, so this driver " | ||||||||||||||||||||||||||||||||||||||||||
| 377 | . "refuses the 'of' key of the for => {} attribute. MySQL gained " | ||||||||||||||||||||||||||||||||||||||||||
| 378 | . "OF tbl_name together with FOR SHARE, NOWAIT and SKIP LOCKED in " | ||||||||||||||||||||||||||||||||||||||||||
| 379 | . "8.0.1; MariaDB has never had it -- its SELECT grammar reads " | ||||||||||||||||||||||||||||||||||||||||||
| 380 | . "[FOR UPDATE lock_option | LOCK IN SHARE MODE lock_option] with " | ||||||||||||||||||||||||||||||||||||||||||
| 381 | . "lock_option: [WAIT n | NOWAIT | SKIP LOCKED], and no OF anywhere. " | ||||||||||||||||||||||||||||||||||||||||||
| 382 | . "The server here is $dialect->{server}. Drop the 'of' key: without " | ||||||||||||||||||||||||||||||||||||||||||
| 383 | . "it the lock covers every table the statement reads, which is what " | ||||||||||||||||||||||||||||||||||||||||||
| 384 | . "these servers do anyway." | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 10 | ▶ | ) unless $dialect->{of}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 8 | ▶ | my @table_list = ref $tables eq 'ARRAY' ? @$tables : ($tables); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 8 | ▶ | if (@table_list) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | my $quoted_tables = join(', ', | ||||||||||||||||||||||||||||||||||||||||||
| 390 | 8 | map { $self->_quote($_) } @table_list | |||||||||||||||||||||||||||||||||||||||||
| 391 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 8 | $lock_clause .= " OF $quoted_tables"; | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | # Add modifier if specified. The name is resolved before the server is | ||||||||||||||||||||||||||||||||||||||||||
| 397 | # asked about it, so an unknown modifier is still reported as unknown | ||||||||||||||||||||||||||||||||||||||||||
| 398 | # rather than as unavailable -- and so the availability question can be | ||||||||||||||||||||||||||||||||||||||||||
| 399 | # asked per modifier, which is what the dialect answers: MySQL got NOWAIT | ||||||||||||||||||||||||||||||||||||||||||
| 400 | # and SKIP LOCKED together in 8.0.1, MariaDB did not (karr #38). | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 28 | ▶ | if ($modifier) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 20 | ▶ | my $mod_sql = $lock_modifiers->{$modifier} | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$lock_modifiers->{$modifier} || $self->throw_exception("Unknown lock modifier '${modifier}' requested")
MC/DC0%0/2
$lock_modifiers->{$modifier} || $self->throw_exception("Unknown lock modifier '${modifier}' requested")
$lock_modifiers->{$modifier}
$self->throw_exception("Unknown lock modifier '${modifier}' requested")
Truth table33%1/3
A || B
A= $lock_modifiers->{$modifier}B= $self->throw_exception("Unknown lock modifier '${modifier}' requested")
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | || $self->throw_exception("Unknown lock modifier '$modifier' requested"); | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | $self->throw_exception( | ||||||||||||||||||||||||||||||||||||||||||
| 406 | "This server has no $mod_sql on a locking read, so this driver refuses " | ||||||||||||||||||||||||||||||||||||||||||
| 407 | . "modifier => '$modifier' in the for => {} attribute. The two products " | ||||||||||||||||||||||||||||||||||||||||||
| 408 | . "drew the line in different places: MySQL gained NOWAIT and SKIP " | ||||||||||||||||||||||||||||||||||||||||||
| 409 | . "LOCKED together in 8.0.1 (Reference Manual 17.7.2.4, 'Locking Read " | ||||||||||||||||||||||||||||||||||||||||||
| 410 | . "Concurrency with NOWAIT and SKIP LOCKED'), while MariaDB gained " | ||||||||||||||||||||||||||||||||||||||||||
| 411 | . "NOWAIT in 10.3 (MDEV-11379) and SKIP LOCKED only in 10.6 " | ||||||||||||||||||||||||||||||||||||||||||
| 412 | . "(MDEV-13115), so a MariaDB in between has the one and not the other. " | ||||||||||||||||||||||||||||||||||||||||||
| 413 | . "The server here is $dialect->{server}. Drop the modifier and the " | ||||||||||||||||||||||||||||||||||||||||||
| 414 | . "locking read waits, which is the only behaviour this server has." | ||||||||||||||||||||||||||||||||||||||||||
| 415 | 19 | ▶ | ) unless $dialect->{$modifier}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 15 | $lock_clause .= " $mod_sql"; | |||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 23 | return " $lock_clause"; | |||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | # Handle simple string types (for backward compatibility) | ||||||||||||||||||||||||||||||||||||||||||
| 424 | 8 | ▶ | my $sql = $lock_types->{$type} | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$lock_types->{$type} || $self->throw_exception("Unknown SELECT .. FOR type '${type}' requested")
MC/DC0%0/2
$lock_types->{$type} || $self->throw_exception("Unknown SELECT .. FOR type '${type}' requested")
$lock_types->{$type}
$self->throw_exception("Unknown SELECT .. FOR type '${type}' requested")
Truth table33%1/3
A || B
A= $lock_types->{$type}B= $self->throw_exception("Unknown SELECT .. FOR type '${type}' requested")
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | || $self->throw_exception("Unknown SELECT .. FOR type '$type' requested"); | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 8 | return " $sql"; | |||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | 38 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | __END__ | ||||||||||||||||||||||||||||||||||||||||||