| 1 | # $Id$ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Data::ObjectDriver::SQL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use base qw( Class::Accessor::Fast ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | __PACKAGE__->mk_accessors(qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | select distinct select_map select_map_reverse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | from joins where bind limit offset group order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | having where_values column_mutator index_hint | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | comment as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 53 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 53 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 53 | my $stmt = $class->SUPER::new(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 53 | $stmt->select([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 53 | $stmt->distinct(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 53 | $stmt->select_map({}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 53 | $stmt->select_map_reverse({}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 53 | $stmt->bind([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 53 | $stmt->from([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 53 | $stmt->where([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 53 | $stmt->where_values({}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 53 | $stmt->having([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 53 | $stmt->joins([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 53 | $stmt->index_hint({}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 53 | $stmt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 13 | ▶ | sub add_select { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_select: called CC=6 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 13 | my $stmt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 13 | my($term, $col) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 13 | push @{ $stmt->select }, $term; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 13 | ▶ | if (blessed($term) && $term->isa('Data::ObjectDriver::SQL')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($term) and $term->isa("Data::ObjectDriver::SQL")
MC/DC0%0/2
builtin::blessed($term) and $term->isa("Data::ObjectDriver::SQL")
builtin::blessed($term)
$term->isa("Data::ObjectDriver::SQL")
Truth table33%1/3
A and B
A= builtin::blessed($term)B= $term->isa("Data::ObjectDriver::SQL")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | my $alias = $col || $term->as || $term->as_sql; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$col || $term->as || $term->as_sql
$col or $term->as
MC/DC0%0/3
$col || $term->as || $term->as_sql
$col
$term->as
$term->as_sql
Truth table0%0/4
A or B || C
A= $colB= $term->asC= $term->as_sql
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $stmt->select_map->{$term} = $alias; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $stmt->select_map_reverse->{$alias} = $term; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 13 | ▶ | $col ||= $term; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$col ||= $term
MC/DC0%0/2
$col ||= $term
$col
$term
Truth table66%2/3
A ||= B
A= $colB= $term
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 13 | $stmt->select_map->{$term} = $col; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 13 | $stmt->select_map_reverse->{$col} = $term; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 8 | ▶ | sub add_join { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_join: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 8 | my $stmt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 8 | my($table, $joins) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 8 | ▶ | push @{ $stmt->joins }, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | table => $table, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | joins => ref($joins) eq 'ARRAY' ? $joins : [ $joins ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | sub add_index_hint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_index_hint: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | my $stmt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | my($table, $hint) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | $stmt->index_hint->{$table} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | type => $hint->{type} || 'USE', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | list => ref($hint->{list}) eq 'ARRAY' ? $hint->{list} : [ $hint->{list} ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$hint->{'type'} || 'USE'
MC/DC0%0/1
$hint->{'type'} || 'USE'
$hint->{'type'}
Truth table50%1/2
A
A= $hint->{'type'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 32 | ▶ | sub as_sql { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_sql: called CC=20 SCAR=31.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 32 | my $stmt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 32 | my $sql = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 32 | my @bind_for_select; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 32 | ▶ | if (@{ $stmt->select }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 14 | $sql .= 'SELECT '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 14 | ▶ | $sql .= 'DISTINCT ' if $stmt->distinct; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 14 | my $select_map = $stmt->select_map; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | $sql .= join(', ', map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 19 | my $col = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 19 | my $alias = $select_map->{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 19 | ▶ | if (blessed($col) && $col->isa('Data::ObjectDriver::SQL')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($col) and $col->isa("Data::ObjectDriver::SQL")
MC/DC0%0/2
builtin::blessed($col) and $col->isa("Data::ObjectDriver::SQL")
builtin::blessed($col)
$col->isa("Data::ObjectDriver::SQL")
Truth table33%1/3
A and B
A= builtin::blessed($col)B= $col->isa("Data::ObjectDriver::SQL")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | push @bind_for_select, @{ $col->{bind} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | @{ $col->{bind} } = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $col->as_subquery($alias); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 19 | ▶ | if ($alias) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 19 | ▶ | /(?:^|\.)\Q$alias\E$/ ? $col : "$col $alias"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $col; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 14 | } @{ $stmt->select }) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 32 | $sql .= 'FROM '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | ## Add any explicit JOIN statements before the non-joined tables. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 32 | my %joined; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 32 | ▶ | my @from = @{ $stmt->from || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$stmt->from || []
MC/DC0%0/1
$stmt->from || []
$stmt->from
Truth table50%1/2
A
A= $stmt->from
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 32 | ▶ | if ($stmt->joins && @{ $stmt->joins }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$stmt->joins and @{$stmt->joins;}
MC/DC50%1/2
$stmt->joins and @{$stmt->joins;}
$stmt->joins
@{$stmt->joins;}
Truth table66%2/3
A and B
A= $stmt->joinsB= @{$stmt->joins;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | my $initial_table_written = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 8 | for my $j (@{ $stmt->joins }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 11 | my($table, $joins) = map { $j->{$_} } qw( table joins ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 11 | $table = $stmt->_add_index_hint($table); ## index hint handling | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 11 | ▶ | $sql .= $table unless $initial_table_written++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 11 | $joined{$table}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 11 | for my $join (@{ $j->{joins} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 13 | $joined{$join->{table}}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | $sql .= ' ' . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | uc($join->{type}) . ' JOIN ' . $join->{table} . ' ON ' . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 13 | $join->{condition}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 8 | @from = grep { ! $joined{ $_ } } @from; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 8 | ▶ | $sql .= ', ' if @from; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 32 | my @bind_for_from; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 32 | ▶ | if (@from) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | $sql .= join ', ', map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 25 | my $from = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 26 | ▶ | if (blessed($from) && $from->isa('Data::ObjectDriver::SQL')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($from) and $from->isa("Data::ObjectDriver::SQL")
MC/DC0%0/2
builtin::blessed($from) and $from->isa("Data::ObjectDriver::SQL")
builtin::blessed($from)
$from->isa("Data::ObjectDriver::SQL")
Truth table33%1/3
A and B
A= builtin::blessed($from)B= $from->isa("Data::ObjectDriver::SQL")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | push @bind_for_from, @{$from->{bind}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | @{$from->{bind}} = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $from->as_subquery; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 26 | $stmt->_add_index_hint($from); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } @from; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 32 | $sql .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 32 | $sql .= $stmt->as_sql_where; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 32 | $sql .= $stmt->as_aggregate('group'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 32 | $sql .= $stmt->as_sql_having; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 32 | $sql .= $stmt->as_aggregate('order'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 32 | $sql .= $stmt->as_limit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 31 | my $comment = $stmt->comment; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 31 | ▶ | if ($comment && $comment =~ /([ 0-9a-zA-Z.:;()_#&,]+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$comment and $comment =~ /([ 0-9a-zA-Z.:;()_#&,]+)/
MC/DC50%1/2
$comment and $comment =~ /([ 0-9a-zA-Z.:;()_#&,]+)/
$comment
$comment =~ /([ 0-9a-zA-Z.:;()_#&,]+)/
Truth table66%2/3
A and B
A= $commentB= $comment =~ /([ 0-9a-zA-Z.:;()_#&,]+)/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 3 | ▶ | $sql .= "-- $1" if $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 31 | @{ $stmt->{bind} } = (@bind_for_select, @bind_for_from, @{ $stmt->{bind} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 31 | return $sql; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | sub as_subquery { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_subquery: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my ($stmt, $alias) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my $subquery = '(' . $stmt->as_sql . ')'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | $alias ||= $stmt->as; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$alias ||= $stmt->as
MC/DC0%0/2
$alias ||= $stmt->as
$alias
$stmt->as
Truth table0%0/3
A ||= B
A= $aliasB= $stmt->as
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if ($alias) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $subquery .= ' '. $alias; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | $subquery; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 32 | ▶ | sub as_limit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_limit: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 32 | my $stmt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 32 | ▶ | my $n = $stmt->limit or | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | return ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | ▶ | die "Non-numerics in limit clause ($n)" if $n =~ /\D/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 3 | ▶ | return sprintf "LIMIT %d%s\n", $n, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | ($stmt->offset ? " OFFSET " . int($stmt->offset) : ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 64 | ▶ | sub as_aggregate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_aggregate: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 64 | my $stmt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 64 | my($set) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 64 | ▶ | if (my $attribute = $stmt->$set()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 10 | ▶ | my $elements = (ref($attribute) eq 'ARRAY') ? $attribute : [ $attribute ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | return uc($set) . ' BY ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 10 | ▶ | . join(', ', map { $_->{column} . ($_->{desc} ? (' ' . $_->{desc}) : '') } @$elements) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 54 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 68 | ▶ | sub as_sql_where { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_sql_where: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 68 | my $stmt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 68 | $stmt->where && @{ $stmt->where } ? | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 68 | ▶ | 'WHERE ' . join(' AND ', @{ $stmt->where }) . "\n" : | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$stmt->where and @{$stmt->where;}
MC/DC50%1/2
$stmt->where and @{$stmt->where;}
$stmt->where
@{$stmt->where;}
Truth table66%2/3
A and B
A= $stmt->whereB= @{$stmt->where;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 32 | ▶ | sub as_sql_having { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_sql_having: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 32 | my $stmt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 32 | $stmt->having && @{ $stmt->having } ? | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 32 | ▶ | 'HAVING ' . join(' AND ', @{ $stmt->having }) . "\n" : | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$stmt->having and @{$stmt->having;}
MC/DC50%1/2
$stmt->having and @{$stmt->having;}
$stmt->having
@{$stmt->having;}
Truth table66%2/3
A and B
A= $stmt->havingB= @{$stmt->having;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 6 | ▶ | sub as_escape { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_escape: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 6 | my ($stmt, $escape_char) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # escape_char can be ''(two quotes), or \\ for mysql and \ for others, but it doesn't accept any injections. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 6 | ▶ | die 'escape_char length must be up to two characters' if defined($escape_char) && length($escape_char) > 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $escape_char and length $escape_char > 2
MC/DC50%1/2
defined $escape_char and length $escape_char > 2
defined $escape_char
length $escape_char > 2
Truth table66%2/3
A and B
A= defined $escape_charB= length $escape_char > 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 5 | return " ESCAPE '$escape_char'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 30 | ▶ | sub add_where { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_where: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 30 | my $stmt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | ## xxx Need to support old range and transform behaviors. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 30 | my($col, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 30 | ▶ | Carp::croak("Invalid/unsafe column name $col") unless $col =~ /^[\w\.]+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 30 | my($term, $bind, $tcol) = $stmt->_mk_term($col, $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 29 | push @{ $stmt->{where} }, "($term)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 29 | push @{ $stmt->{bind} }, @$bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 29 | $stmt->where_values->{$tcol} = $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 9 | ▶ | sub add_complex_where { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_complex_where: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 9 | my $stmt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 9 | my ($terms) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 9 | my ($where, $bind) = $stmt->_parse_array_terms($terms); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 9 | ▶ | if ($where) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 6 | push @{ $stmt->{where} }, $where; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 6 | push @{ $stmt->{bind} }, @$bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 11 | ▶ | sub _parse_array_terms { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_array_terms: called CC=12 SCAR=26.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 11 | my $stmt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 11 | my ($term_list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 11 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 11 | my $logic = 'AND'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 11 | my @bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 11 | foreach my $t ( @$term_list ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 13 | ▶ | if (! ref $t ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | $logic = $1 if uc($t) =~ m/^-?(OR|AND|OR_NOT|AND_NOT)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | $logic =~ s/_/ /; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 13 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 13 | ▶ | if (ref $t eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # bag of terms to apply $logic with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 11 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 11 | foreach my $t2 ( keys %$t ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 10 | my ($term, $bind, $col) = $stmt->_mk_term($t2, $t->{$t2}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 10 | $stmt->where_values->{$col} = $t->{$t2}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 10 | ▶ | if ($term) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 10 | push @out, "($term)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 10 | push @bind, @$bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 11 | ▶ | $out .= '(' . join(" AND ", @out) . ")" if @out; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | elsif (ref $t eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # another array of terms to process! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 2 | my ($where, $bind) = $stmt->_parse_array_terms( $t ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 2 | ▶ | if ($where) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | push @bind, @$bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $out = '(' . $where . ')'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 13 | ▶ | push @out, (@out ? ' ' . $logic . ' ' : '') . $out if $out; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 11 | return (join("", @out), \@bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | sub has_where { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_where: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my $stmt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my($col, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # TODO: should check if the value is same with $val? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | exists $stmt->where_values->{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | ▶ | sub add_having { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_having: called CC=4 SCAR=14.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 1 | my $stmt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 1 | my($col, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # Carp::croak("Invalid/unsafe column name $col") unless $col =~ /^[\w\.]+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | ▶ | if (my $orig = $stmt->select_map_reverse->{$col}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | ▶ | if (blessed($orig) && $orig->isa('Data::ObjectDriver::SQL')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($orig) and $orig->isa("Data::ObjectDriver::SQL")
MC/DC0%0/2
builtin::blessed($orig) and $orig->isa("Data::ObjectDriver::SQL")
builtin::blessed($orig)
$orig->isa("Data::ObjectDriver::SQL")
Truth table33%1/3
A and B
A= builtin::blessed($orig)B= $orig->isa("Data::ObjectDriver::SQL")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # do nothins | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | $col = $orig; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 1 | my($term, $bind) = $stmt->_mk_term($col, $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 1 | push @{ $stmt->{having} }, "($term)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | push @{ $stmt->{bind} }, @$bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 62 | ▶ | sub _mk_term { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mk_term: called CC=31 SCAR=35.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 62 | my $stmt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 62 | my($col, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 62 | my $term = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 62 | my (@bind, $m); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 62 | ▶ | if (ref($val) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 11 | ▶ | if (ref $val->[0] or (($val->[0] || '') eq '-and')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
ref $val->[0] or ($val->[0] || "") eq "-and"
$val->[0] || ''
MC/DC100%2/2
ref $val->[0] or ($val->[0] || "") eq "-and"
ref $val->[0]
$val->[0]
Truth table100%3/3
A or B
A= ref $val->[0]B= $val->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 9 | my $logic = 'OR'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 9 | my @values = @$val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 9 | ▶ | if ($val->[0] eq '-and') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 5 | $logic = 'AND'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 5 | shift @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 9 | my @terms; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 9 | for my $v (@values) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 21 | my($term, $bind) = $stmt->_mk_term($col, $v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 21 | push @terms, "($term)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 21 | push @bind, @$bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 9 | $term = join " $logic ", @terms; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 2 | ▶ | $col = $m->($col) if $m = $stmt->column_mutator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 2 | $term = $stmt->_mk_term_arrayref($col, 'IN', $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 2 | @bind = @$val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } elsif (ref($val) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 20 | ▶ | my $c = $val->{column} || $col; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$val->{'column'} || $col
MC/DC0%0/2
$val->{'column'} || $col
$val->{'column'}
$col
Truth table66%2/3
A || B
A= $val->{'column'}B= $col
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 20 | ▶ | $c = $m->($c) if $m = $stmt->column_mutator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 20 | my $op = uc $val->{op}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 20 | ▶ | if (($op eq 'IN' or $op eq 'NOT IN') and ref $val->{value} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%6/6
$op eq "IN" || $op eq "NOT IN" and ref $val->{"value"} eq "ARRAY"
$op eq "IN" or $op eq "NOT IN"
MC/DC100%3/3
$op eq "IN" || $op eq "NOT IN" and ref $val->{"value"} eq "ARRAY"
$op eq "IN"
$op eq "NOT IN"
ref $val->{"value"} eq "ARRAY"
Truth table80%4/5
A or B and C
A= $op eq "IN"B= $op eq "NOT IN"C= ref $val->{"value"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 2 | $term = $stmt->_mk_term_arrayref($c, $op, $val->{value}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 2 | push @bind, @{$val->{value}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | ▶ | } elsif (($op eq 'IN' or $op eq 'NOT IN') and ref $val->{value} eq 'REF') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$op eq "IN" || $op eq "NOT IN" and ref $val->{"value"} eq "REF"
$op eq "IN" or $op eq "NOT IN"
MC/DC66%2/3
$op eq "IN" || $op eq "NOT IN" and ref $val->{"value"} eq "REF"
$op eq "IN"
$op eq "NOT IN"
ref $val->{"value"} eq "REF"
Truth table60%3/5
A or B and C
A= $op eq "IN"B= $op eq "NOT IN"C= ref $val->{"value"} eq "REF"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | my @values = @{${$val->{value}}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 1 | $term = "$c $op (" . (shift @values) . ")"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 1 | push @bind, @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | ▶ | } elsif ($op eq 'BETWEEN' and ref $val->{value} eq 'ARRAY') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$op eq "BETWEEN" and ref $val->{"value"} eq "ARRAY"
MC/DC50%1/2
$op eq "BETWEEN" and ref $val->{"value"} eq "ARRAY"
$op eq "BETWEEN"
ref $val->{"value"} eq "ARRAY"
Truth table66%2/3
A and B
A= $op eq "BETWEEN"B= ref $val->{"value"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | ▶ | Carp::croak "USAGE: foo => {op => 'BETWEEN', value => [\$a, \$b]}" if @{$val->{value}} != 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | $term = "$c $op ? AND ?"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 1 | push @bind, @{$val->{value}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 16 | my $value = $val->{value}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 16 | ▶ | if (ref $value eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 1 | $term = "$c $val->{op} " . $$value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | ▶ | } elsif (blessed($value) && $value->isa('Data::ObjectDriver::SQL')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
builtin::blessed($value) and $value->isa("Data::ObjectDriver::SQL")
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Data::ObjectDriver::SQL")
builtin::blessed($value)
$value->isa("Data::ObjectDriver::SQL")
Truth table33%1/3
A and B
A= builtin::blessed($value)B= $value->isa("Data::ObjectDriver::SQL")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | local $value->{as} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | $term = "$c $val->{op} ". $value->as_subquery; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | push @bind, @{$value->{bind}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 15 | $term = "$c $val->{op} ?"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 15 | ▶ | $term .= $stmt->as_escape($val->{escape}) if $val->{escape} && $op =~ /^(?:NOT\s+)?I?LIKE$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$val->{"escape"} and $op =~ /^(?:NOT\s+)?I?LIKE$/
MC/DC50%1/2
$val->{"escape"} and $op =~ /^(?:NOT\s+)?I?LIKE$/
$val->{"escape"}
$op =~ /^(?:NOT\s+)?I?LIKE$/
Truth table66%2/3
A and B
A= $val->{"escape"}B= $op =~ /^(?:NOT\s+)?I?LIKE$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 14 | push @bind, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } elsif (ref($val) eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 9 | ▶ | $col = $m->($col) if $m = $stmt->column_mutator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 9 | $term = "$col $$val"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } elsif (ref($val) eq 'REF') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 1 | ▶ | $col = $m->($col) if $m = $stmt->column_mutator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 1 | my @values = @{$$val}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 1 | $term = "$col " . (shift @values); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 1 | push @bind, @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 21 | ▶ | $col = $m->($col) if $m = $stmt->column_mutator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 21 | ▶ | if (defined $val) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 20 | $term = "$col = ?"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 20 | push @bind, $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | $term = "$col IS NULL"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 61 | ($term, \@bind, $col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 4 | ▶ | sub _mk_term_arrayref { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mk_term_arrayref: called CC=4 SCAR=15.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 4 | my ($stmt, $col, $op, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 4 | ▶ | if (@$val) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 3 | return "$col $op (".join(',', ('?') x scalar @$val).')'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 1 | ▶ | if ($op eq 'IN') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 1 | return '0 = 1'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } elsif ($op eq 'NOT IN') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | return '1 = 1'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 37 | ▶ | sub _add_index_hint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_index_hint: called CC=6 SCAR=19.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 37 | my $stmt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 37 | my ($tbl_name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 37 | my $hint = $stmt->index_hint->{$tbl_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 37 | ▶ | return $tbl_name unless $hint && ref($hint) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$hint and ref $hint eq "HASH"
MC/DC50%1/2
$hint and ref $hint eq "HASH"
$hint
ref $hint eq "HASH"
Truth table66%2/3
A and B
A= $hintB= ref $hint eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 3 | ▶ | if ($hint->{list} && @{ $hint->{list} }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$hint->{"list"} and @{$hint->{"list"};}
MC/DC0%0/2
$hint->{"list"} and @{$hint->{"list"};}
$hint->{"list"}
@{$hint->{"list"};}
Truth table33%1/3
A and B
A= $hint->{"list"}B= @{$hint->{"list"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | return $tbl_name . ' ' . uc($hint->{type} || 'USE') . ' INDEX (' . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 3 | ▶ | join (',', @{ $hint->{list} }) . | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$hint->{'type'} || 'USE'
MC/DC0%0/1
$hint->{'type'} || 'USE'
$hint->{'type'}
Truth table50%1/2
A
A= $hint->{'type'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | ')'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | return $tbl_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||