| 1 | package # Hide from PAUSE | ||||||||||||||||||||||||||||||||||||||||||
| 2 | DBIx::Class::SQLMaker::MySQL; | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use base qw( DBIx::Class::SQLMaker ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # MySQL does not understand the standard INSERT INTO $table DEFAULT VALUES | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # Adjust SQL here instead | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub insert { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | if (! $_[1] or (ref $_[1] eq 'HASH' and !keys %{$_[1]} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $_[1] or ref $_[1] eq "HASH" and not keys %{$_[1];}
ref $_[1] eq "HASH" and not keys %{$_[1];}
MC/DC0%0/3
not $_[1] or ref $_[1] eq "HASH" and not keys %{$_[1];}
not $_[1]
ref $_[1] eq "HASH"
not keys %{$_[1];}
Truth table0%0/4
not(A) or B and not(C)
A= not $_[1]B= ref $_[1] eq "HASH"C= not keys %{$_[1];}
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | my $table = $self->_quote($_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | return "INSERT INTO ${table} () VALUES ()" | |||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | return $self->next::method (@_); | |||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | # Allow STRAIGHT_JOIN's | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 9 | ▶ | sub _generate_join_clause { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_join_clause: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 9 | my ($self, $join_type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 9 | ▶ | if( $join_type && $join_type =~ /^STRAIGHT\z/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$join_type and $join_type =~ /^STRAIGHT\z/i
MC/DC50%1/2
$join_type and $join_type =~ /^STRAIGHT\z/i
$join_type
$join_type =~ /^STRAIGHT\z/i
Truth table66%2/3
A and B
A= $join_typeB= $join_type =~ /^STRAIGHT\z/i
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | return ' STRAIGHT_JOIN ' | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 7 | return $self->next::method($join_type); | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | my $force_double_subq; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 9 | ▶ | $force_double_subq = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 9 | my ($self, $sql) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 9 | require Text::Balanced; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 9 | my $new_sql; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 9 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 19 | my ($prefix, $parenthesized); | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 19 | ($parenthesized, $sql, $prefix) = do { | |||||||||||||||||||||||||||||||||||||||||
| 46 | # idiotic design - writes to $@ but *DOES NOT* throw exceptions | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 19 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 19 | Text::Balanced::extract_bracketed( $sql, '()', qr/[^\(]*/ ); | |||||||||||||||||||||||||||||||||||||||||
| 49 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | # this is how an error is indicated, in addition to crapping in $@ | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 19 | ▶ | last unless $parenthesized; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 10 | ▶ | if ($parenthesized =~ $self->{_modification_target_referenced_re}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | # is this a select subquery? | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 10 | ▶ | if ( $parenthesized =~ /^ \( \s* SELECT \s+ /xi ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 5 | $parenthesized = "( SELECT * FROM $parenthesized `_forced_double_subquery` )"; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # then drill down until we find it (if at all) | ||||||||||||||||||||||||||||||||||||||||||
| 60 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | $parenthesized =~ s/^ \( (.+) \) $/$1/x; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 5 | $parenthesized = join ' ', '(', $self->$force_double_subq( $parenthesized ), ')'; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 10 | $new_sql .= $prefix . $parenthesized; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 9 | return $new_sql . $sql; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | # short-circuit unless understood identifier | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | ▶ | return $self->next::method(@_) unless $self->{_modification_target_referenced_re}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | my ($sql, @bind) = $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | $sql = $self->$force_double_subq($sql) | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | ▶ | if $sql =~ $self->{_modification_target_referenced_re}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | return ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | ▶ | sub delete { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | # short-circuit unless understood identifier | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | return $self->next::method(@_) unless $self->{_modification_target_referenced_re}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | my ($sql, @bind) = $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | $sql = $self->$force_double_subq($sql) | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | ▶ | if $sql =~ $self->{_modification_target_referenced_re}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | return ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | # LOCK IN SHARE MODE | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 3 | my $for_syntax = { | |||||||||||||||||||||||||||||||||||||||||
| 102 | update => 'FOR UPDATE', | ||||||||||||||||||||||||||||||||||||||||||
| 103 | shared => 'LOCK IN SHARE MODE' | ||||||||||||||||||||||||||||||||||||||||||
| 104 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub _lock_select { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lock_select: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my ($self, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | my $sql = $for_syntax->{$type} | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$for_syntax->{$type} || $self->throw_exception("Unknown SELECT .. FOR type '${type}' requested")
MC/DC0%0/2
$for_syntax->{$type} || $self->throw_exception("Unknown SELECT .. FOR type '${type}' requested")
$for_syntax->{$type}
$self->throw_exception("Unknown SELECT .. FOR type '${type}' requested")
Truth table0%0/3
A || B
A= $for_syntax->{$type}B= $self->throw_exception("Unknown SELECT .. FOR type '${type}' requested")
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | || $self->throw_exception("Unknown SELECT .. FOR type '$type' requested"); | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | return " $sql"; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||