| 1 | package SQL::Abstract::More; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # no "use parent ..." here -- for the moment the inheritance is specified dynamically in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # import() method -- inheriting either from SQL::Abstract or SQL::Abstract::Classic. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # This is deprecated and will no longer be supported in the next version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use mro 'c3'; # implements next::method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use Params::Validate qw/validate SCALAR SCALARREF CODEREF ARRAYREF HASHREF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | UNDEF BOOLEAN/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use Scalar::Util qw/blessed reftype/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # remove all previously defined or imported functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 11 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # declare error-reporting functions from SQL::Abstract | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | sub puke(@); sub belch(@); # these will be defined later in import() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 11 | our $VERSION = '1.49_01'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 11 | our @ISA; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 14 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 14 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # the parent class may be specified from an environment variable ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 14 | my $parent_sqla = $ENV{SQL_ABSTRACT_MORE_EXTENDS}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # ... or from param -extends => .. when calling import() ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 14 | ▶ | $parent_sqla = $_[1] if @_ >= 2 && $_[0] eq '-extends'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ >= 2 and $_[0] eq "-extends"
MC/DC50%1/2
@_ >= 2 and $_[0] eq "-extends"
@_ >= 2
$_[0] eq "-extends"
Truth table66%2/3
A and B
A= @_ >= 2B= $_[0] eq "-extends"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # ... but choosing the parent is deprecated! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 14 | ▶ | ! $parent_sqla | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | or warn "explicitly specification of $parent_sqla as parent class to SQL::Abstract::More is deprecated; " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | . "future versions will no longer offer that possibility"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # default parent class .. this will be mandatory in the next version. Later versions may have no parent at all. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 14 | ▶ | $parent_sqla ||= 'SQL::Abstract::Classic'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$parent_sqla ||= "SQL::Abstract::Classic"
MC/DC100%1/1
$parent_sqla ||= "SQL::Abstract::Classic"
$parent_sqla
Truth table100%2/2
A
A= $parent_sqla
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # syntactic sugar : 'Classic' is expanded into SQLA::Classic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 14 | ▶ | $parent_sqla = 'SQL::Abstract::Classic' if $parent_sqla eq 'Classic'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # make sure that import() is never called with different parents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 14 | ▶ | if (my $already_isa = $ISA[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | $already_isa eq $parent_sqla | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | or die "cannot use SQL::Abstract::More -extends => '$parent_sqla', " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | . "this module was already loaded with -extends => '$already_isa'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # the rest of the import() job was already performed, so just return from here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # load the parent, inherit from it, import puke() and belch() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 11 | ▶ | eval qq{use parent '$parent_sqla'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | *puke = \\&${parent_sqla}::puke; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | *belch = \\&${parent_sqla}::belch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # local override of some methods for insert() and update() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 11 | _setup_insert_inheritance($parent_sqla); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 11 | _setup_update_inheritance($parent_sqla); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # Utility functions -- not methods -- declared _after_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # namespace::clean so that they can remain visible by external | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # modules. In particular, DBIx::DataModel imports these functions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # shallow_clone(): copies of the top-level keys and values, blessed into the same class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 6 | ▶ | sub shallow_clone { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shallow_clone: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 6 | my ($orig, %override) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 6 | ▶ | my $class = ref $orig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | or puke "arg must be an object"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 6 | my $clone = {%$orig, %override}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 6 | return bless $clone, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # does(): cheap version of Scalar::Does | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 11 | my %meth_for = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ARRAY => '@{}', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | HASH => '%{}', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | SCALAR => '${}', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | CODE => '&{}', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1424 | ▶ | sub does ($$) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
does: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1424 | my ($data, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1424 | my $reft = reftype $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | return defined $reft && $reft eq $type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1424 | ▶ | || blessed $data && overload::Method($data, $meth_for{$type}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%6/9
defined $reft && $reft eq $type || builtin::blessed($data) && overload::Method($data, $meth_for{$type})
defined $reft and $reft eq $type
builtin::blessed($data) and overload::Method($data, $meth_for{$type})
MC/DC50%2/4
defined $reft && $reft eq $type || builtin::blessed($data) && overload::Method($data, $meth_for{$type})
defined $reft
$reft eq $type
builtin::blessed($data)
overload::Method($data, $meth_for{$type})
Truth table42%3/7
A and B || C and D
A= defined $reftB= $reft eq $typeC= builtin::blessed($data)D= overload::Method($data, $meth_for{$type})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # global variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # builtin methods for "Limit-Offset" dialects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | my %limit_offset_dialects = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 10 | ▶ | LimitOffset => sub {my ($self, $limit, $offset) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 10 | ▶ | $offset ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$offset ||= 0
MC/DC100%1/1
$offset ||= 0
$offset
Truth table100%2/2
A
A= $offset
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 10 | return "LIMIT ? OFFSET ?", $limit, $offset;}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | ▶ | LimitXY => sub {my ($self, $limit, $offset) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | ▶ | $offset ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$offset ||= 0
MC/DC0%0/1
$offset ||= 0
$offset
Truth table50%1/2
A
A= $offset
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | return "LIMIT ?, ?", $offset, $limit;}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | LimitYX => sub {my ($self, $limit, $offset) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | $offset ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$offset ||= 0
MC/DC0%0/1
$offset ||= 0
$offset
Truth table0%0/2
A
A= $offset
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | return "LIMIT ?, ?", $limit, $offset;}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | ▶ | OffsetFetchRows => sub {my ($self, $limit, $offset) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 2 | ▶ | $offset ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$offset ||= 0
MC/DC0%0/1
$offset ||= 0
$offset
Truth table50%1/2
A
A= $offset
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 2 | return "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY", $offset, $limit;}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 2 | ▶ | RowNum => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | my ($self, $limit, $offset) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # HACK below borrowed from SQL::Abstract::Limit. Not perfect, though, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # because it brings back an additional column. Should borrow from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # DBIx::Class::SQLMaker::LimitDialects, which does the proper job ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # but it says : "!!! THIS IS ALSO HORRIFIC !!! /me ashamed"; so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # I'll only take it as last resort; still exploring other ways. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # See also L<DBIx::DataModel> : within that ORM an additional layer is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # added to take advantage of Oracle scrollable cursors (for Oracle < 12c). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 2 | my $sql = "SELECT * FROM (" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | . "SELECT subq_A.*, ROWNUM rownum__index FROM (%s) subq_A " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | . "WHERE ROWNUM <= ?" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | . ") subq_B WHERE rownum__index >= ?"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 11 | ▶ | no warnings 'uninitialized'; # in case $limit or $offset is undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # row numbers start at 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | return $sql, $offset + $limit, $offset + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 11 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # builtin join operators with associated sprintf syntax | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 11 | my %common_join_syntax = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | '<=>' => '%s INNER JOIN %s ON %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | '=>' => '%s LEFT OUTER JOIN %s ON %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | '<=' => '%s RIGHT OUTER JOIN %s ON %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | '==' => '%s NATURAL JOIN %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | '>=<' => '%s FULL OUTER JOIN %s ON %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 11 | my %right_assoc_join_syntax = %common_join_syntax; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 11 | s/JOIN %s/JOIN (%s)/ foreach values %right_assoc_join_syntax; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # specification of parameters accepted by the new() method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 11 | my %params_for_new = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | table_alias => {type => SCALAR|CODEREF, default => '%s AS %s' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | column_alias => {type => SCALAR|CODEREF, default => '%s AS %s' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | limit_offset => {type => SCALAR|CODEREF, default => 'LimitOffset' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | join_syntax => {type => HASHREF, default => \%common_join_syntax}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | join_assoc_right => {type => BOOLEAN, default => 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | max_members_IN => {type => SCALAR, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | multicols_sep => {type => SCALAR|SCALARREF, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | has_multicols_in_SQL => {type => BOOLEAN, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | sql_dialect => {type => SCALAR, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | select_implicitly_for => {type => SCALAR|UNDEF, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # builtin collection of parameters, for various databases | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 11 | my %sql_dialects = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | MsAccess => {join_assoc_right => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | join_syntax => \%right_assoc_join_syntax}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | BasisJDBC => {column_alias => "%s %s", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | max_members_IN => 255 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | MySQL_old => {limit_offset => "LimitXY" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | Oracle => {limit_offset => "RowNum", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | max_members_IN => 999, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | table_alias => '%s %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | column_alias => '%s %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | has_multicols_in_SQL => 1, }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 11 | $sql_dialects{Oracle12c} = {%{$sql_dialects{Oracle}}, limit_offset => "OffsetFetchRows"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # operators for compound queries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 11 | my @set_operators = qw/union union_all intersect minus except/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # specification of parameters accepted by select, insert, update, delete | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | my %params_for_select = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | -columns => {type => SCALAR|ARRAYREF, default => '*'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | -from => {type => SCALAR|SCALARREF|ARRAYREF}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | -where => {type => SCALAR|ARRAYREF|HASHREF, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 11 | (map {-$_ => {type => ARRAYREF, optional => 1}} @set_operators), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | -group_by => {type => SCALAR|ARRAYREF, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | -having => {type => SCALAR|ARRAYREF|HASHREF, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | -order_by => {type => SCALAR|ARRAYREF|HASHREF, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | -page_size => {type => SCALAR, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | -page_index => {type => SCALAR, optional => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | depends => '-page_size'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | -limit => {type => SCALAR, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | -offset => {type => SCALAR, optional => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | depends => '-limit'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | -for => {type => SCALAR|UNDEF, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | -want_details => {type => BOOLEAN, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | -as => {type => SCALAR, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 11 | my %params_for_insert = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | -into => {type => SCALAR}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | -values => {type => SCALAR|ARRAYREF|HASHREF, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | -select => {type => HASHREF, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | -columns => {type => ARRAYREF, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | -returning => {type => SCALAR|ARRAYREF|HASHREF, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | -add_sql => {type => SCALAR, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 11 | my %params_for_update = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | -table => {type => SCALAR|SCALARREF|ARRAYREF}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | -set => {type => HASHREF}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | -where => {type => SCALAR|ARRAYREF|HASHREF, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | -order_by => {type => SCALAR|ARRAYREF|HASHREF, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | -limit => {type => SCALAR, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | -returning => {type => SCALAR|ARRAYREF|HASHREF, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | -add_sql => {type => SCALAR, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 11 | my %params_for_delete = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | -from => {type => SCALAR}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | -where => {type => SCALAR|ARRAYREF|HASHREF, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | -order_by => {type => SCALAR|ARRAYREF|HASHREF, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | -limit => {type => SCALAR, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | -add_sql => {type => SCALAR, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 11 | my %params_for_WITH = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | -table => {type => SCALAR}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | -columns => {type => SCALAR|ARRAYREF, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | -as_select => {type => HASHREF}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | -final_clause => {type => SCALAR, optional => 1}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # object creation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 28 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=16 SCAR=28.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 28 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # make sure @ISA is populated, in case import() was not already called | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 28 | ▶ | $class->import() if !@ISA; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # accept params either as hash or as hashref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | my %params = does($_[0], 'HASH') ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # extract params for this subclass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 28 | my %more_params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 28 | foreach my $key (keys %params_for_new) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 280 | ▶ | $more_params{$key} = delete $params{$key} if exists $params{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # import params from SQL dialect, if any ... but explict params above had precedence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 28 | my $dialect = delete $more_params{sql_dialect}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 28 | ▶ | if ($dialect) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 6 | ▶ | my $dialect_params = $sql_dialects{$dialect} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | or puke "no such sql dialect: $dialect"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 6 | ▶ | $more_params{$_} ||= $dialect_params->{$_} foreach keys %$dialect_params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$more_params{$_} ||= $dialect_params->{$_}
MC/DC0%0/2
$more_params{$_} ||= $dialect_params->{$_}
$more_params{$_}
$dialect_params->{$_}
Truth table33%1/3
A ||= B
A= $more_params{$_}B= $dialect_params->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # check parameters for this class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 28 | my @more_params = %more_params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 28 | my $more_self = validate(@more_params, \%params_for_new); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # check some of the params for parent -- because SQLA doesn't do it :-( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | !$params{quote_char} || exists $params{name_sep} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 28 | ▶ | or belch "when 'quote_char' is present, 'name_sep' should be present too"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $params{"quote_char"} or exists $params{"name_sep"}
MC/DC0%0/2
not $params{"quote_char"} or exists $params{"name_sep"}
not $params{"quote_char"}
exists $params{"name_sep"}
Truth table66%2/3
not(A) or B
A= not $params{"quote_char"}B= exists $params{"name_sep"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # call parent constructor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 28 | my $self = $class->next::method(%params); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # inject additional attributes into $self | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 28 | $self->{$_} = $more_self->{$_} foreach keys %$more_self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # arguments supplied as scalars are transformed into coderefs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 28 | ▶ | ref $self->{column_alias} or $self->_make_aliasing_sub('column_alias'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 28 | ▶ | ref $self->{table_alias} or $self->_make_aliasing_sub('table_alias'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 28 | ▶ | ref $self->{limit_offset} or $self->_choose_LIMIT_OFFSET_dialect; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # compute the regex for parsing join specifications - depending on 'join_syntax' attribute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 178 | ▶ | my @join_ops = sort {length($b) <=> length($a) || $a cmp $b} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
length $b <=> length $a || $a cmp $b
MC/DC0%0/2
length $b <=> length $a || $a cmp $b
length $b <=> length $a
$a cmp $b
Truth table66%2/3
A || B
A= length $b <=> length $aB= $a cmp $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 28 | keys %{$self->{join_syntax}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 28 | my $joined_ops = join '|', map quotemeta, @join_ops; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 28 | $self->{join_regex} = qr[ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | ^ # initial anchor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | ($joined_ops)? # $1: join operator (i.e. '<=>', '=>', etc.)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | ([[{])? # $2: opening '[' or '{' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | (.*?) # $3: content of brackets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | []}]? # closing ']' or '}' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | $ # final anchor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | ]x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 28 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # support for WITH or WITH RECURSIVE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 6 | ▶ | sub with { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
with: called CC=10 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | ! $self->{WITH} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 6 | ▶ | or puke "calls to methods with() or with_recursive() cannot be chained"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | @_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 6 | ▶ | or puke "->with() : missing arguments"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # create a copy of the current object with an additional attribute WITH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 6 | my $clone = shallow_clone($self, WITH => {sql => "", bind => []}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # assemble SQL and bind values for each table expression | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 6 | ▶ | my @table_expressions = does($_[0], 'ARRAY') ? @_ : ( [ @_]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 6 | foreach my $table_expression (@table_expressions) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 7 | my %args = validate(@$table_expression, \%params_for_WITH); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 7 | ▶ | my @cols = does($args{-columns}, 'ARRAY') ? @{$args{-columns}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | : $args{-columns} ? ($args{-columns}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 7 | ▶ | : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 7 | my ($sql, @bind) = $self->select(%{$args{-as_select}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 7 | ▶ | $clone->{WITH}{sql} .= ", " if $clone->{WITH}{sql}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 7 | $clone->{WITH}{sql} .= $self->_quote($args{-table}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 7 | ▶ | $clone->{WITH}{sql} .= "(" . join(", ", map {$self->_quote($_)} @cols) . ")" if @cols; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 7 | $clone->{WITH}{sql} .= " AS ($sql) "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 7 | ▶ | $clone->{WITH}{sql} .= $args{-final_clause} . " " if $args{-final_clause}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 7 | push @{$clone->{WITH}{bind}}, @bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # add the initial keyword WITH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 6 | substr($clone->{WITH}{sql}, 0, 0) = 'WITH '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 6 | return $clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 5 | ▶ | sub with_recursive { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
with_recursive: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 5 | my $new_instance = $self->with(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 5 | $new_instance->{WITH}{sql} =~ s/^WITH\b/WITH RECURSIVE/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 5 | return $new_instance; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 193 | ▶ | sub _prepend_WITH_clause { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prepend_WITH_clause: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 193 | my ($self, $ref_sql, $ref_bind) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 193 | ▶ | return if !$self->{WITH}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 10 | substr($$ref_sql, 0, 0) = $self->{WITH}{sql}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 10 | unshift @$ref_bind, @{$self->{WITH}{bind}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # the select method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 140 | ▶ | sub select { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select: called CC=17 SCAR=28.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 140 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | # if this method was called with positional args, just delegate to the parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 140 | ▶ | return $self->next::method(@_) if !&_called_with_named_args; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # parse arguments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 136 | my %args = validate(@_, \%params_for_select); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | # infrastructure for collecting fragments of sql and bind args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 136 | my ($sql, @bind) = (""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 136 | ▶ | my $add_sql_bind = sub {$sql .= shift; push @bind, @_}; # closure to add to ($sql, @bind) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | # parse columns and datasource | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 136 | my $from = $self->_parse_datasource($args{-from}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 136 | my ($cols, $post_select, $cols_bind, $aliased_columns) = $self->_parse_columns($args{-columns}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | # parse the WHERE conditions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 136 | my ($where_sql, @where_bind) = $self->where($args{-where}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | # assemble the SELECT statement | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 136 | ▶ | my $fields = ref $cols ? join ", ", @$cols : $cols; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 136 | my $select_sql = join(' ', $self->_sqlcase('select'), $fields, $self->_sqlcase('from'), $from->{sql}) . $where_sql; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 136 | $add_sql_bind->($select_sql, @$cols_bind, @{$from->{bind}}, @where_bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # add @post_select clauses if needed (for ex. -distinct) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 136 | my $all_post_select = join " ", @$post_select; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 136 | ▶ | $sql =~ s[^SELECT ][SELECT $all_post_select ]i if $all_post_select; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # add set operators (UNION, INTERSECT, etc) if needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 136 | foreach my $set_op (@set_operators) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 680 | ▶ | if (my $val_set_op = $args{-$set_op}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 16 | my ($sql_set_op, @bind_set_op) = $self->_parse_set_operator($set_op => $val_set_op, $args{-columns}, $args{-from}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 16 | $add_sql_bind->($sql_set_op, @bind_set_op); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | # add GROUP BY if needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 136 | ▶ | if ($args{-group_by}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 8 | my $sql_grp = $self->where(undef, $args{-group_by}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 8 | $sql_grp =~ s/\bORDER\b/GROUP/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 8 | $add_sql_bind->($sql_grp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # add HAVING if needed (often together with -group_by, but not always) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 136 | ▶ | if ($args{-having}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 5 | my ($sql_having, @bind_having) = $self->where($args{-having}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 5 | $sql_having =~ s/\bWHERE\b/HAVING/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 5 | $add_sql_bind->(" $sql_having", @bind_having); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # add ORDER BY if needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 136 | ▶ | if (my $order = $args{-order_by}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 15 | $add_sql_bind->($self->_order_by($order)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | # add pagination if needed (either -page_* args or -limit/-offset) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 136 | ▶ | $self->_translate_page_into_limit_offset(\%args) if $args{-page_index} or $args{-page_size}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args{"-page_index"} or $args{"-page_size"}
MC/DC50%1/2
$args{"-page_index"} or $args{"-page_size"}
$args{"-page_index"}
$args{"-page_size"}
Truth table66%2/3
A or B
A= $args{"-page_index"}B= $args{"-page_size"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 136 | ▶ | if (defined $args{-limit}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 10 | my ($limit_sql, @limit_bind) = $self->limit_offset(@args{qw/-limit -offset/}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 10 | ▶ | if ($limit_sql =~ /%s/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 2 | $sql = sprintf $limit_sql, $sql; # rewrite the whole $sql | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 2 | push @bind, @limit_bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 8 | $add_sql_bind->(" $limit_sql", @limit_bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | # add FOR clause if needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 136 | ▶ | my $for = exists $args{-for} ? $args{-for} : $self->{select_implicitly_for}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 136 | ▶ | $add_sql_bind->(" FOR $for") if $for; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | # add alias if select() is used as a subquery | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 136 | ▶ | if (my $alias = $args{-as}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 8 | $sql = "($sql)|$alias"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | # initial WITH clause | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 136 | $self->_prepend_WITH_clause(\$sql, \@bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | # return results | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | return $args{-want_details} ? {aliased_tables => $from->{aliased_tables}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 136 | ▶ | aliased_columns => $aliased_columns, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | sql => $sql, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | bind => \@bind} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | : ($sql, @bind); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 136 | ▶ | sub _parse_columns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_columns: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 136 | my ($self, $columns) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | # the -columns arg can be an arrayref or a plain scalar => unify into an array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 136 | ▶ | my @cols = ref $columns ? @$columns : ($columns); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | # initial members of the columns list starting with "-" are extracted into a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | # separate list @post_select, later re-injected into the SQL (for ex. '-distinct') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 136 | my @post_select; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 136 | ▶ | push @post_select, shift @cols while @cols && $cols[0] =~ s/^-//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@cols and $cols[0] =~ s/^-//
MC/DC50%1/2
@cols and $cols[0] =~ s/^-//
@cols
$cols[0] =~ s/^-//
Truth table66%2/3
A and B
A= @colsB= $cols[0] =~ s/^-//
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | # loop over columns, handling aliases and subqueries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 136 | my @cols_bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | my %aliased_columns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 136 | foreach my $col (@cols) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | # deal with subquery of shape \ [$sql, @bind] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 205 | ▶ | if (_is_subquery($col)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 6 | my ($sql, @col_bind) = @$$col; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 6 | $col = _parenthesize_select($sql); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 6 | push @cols_bind, @col_bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | # check for a column alias; if present, register it in the alias table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 205 | ($col, my $alias) = $self->_parse_alias($col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 205 | ▶ | $aliased_columns{$alias} = $col if $alias ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | # quote the column SQL if necessary - excluding expressions with parens or commas | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | # (such as SQL functions or parenthesized subqueries) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 205 | ▶ | $col = $self->_quote($col) unless $col =~ /[(),]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | # insert SQL aliasing if necessary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 205 | ▶ | $col = $self->column_alias($col, $self->_quote($alias)) if $alias; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 136 | return (\@cols, \@post_select, \@cols_bind, \%aliased_columns); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 16 | ▶ | sub _parse_set_operator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_set_operator: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 16 | my ($self, $set_op, $val_set_op, $cols, $from) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 16 | my %sub_args = @$val_set_op; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 16 | ▶ | $sub_args{-columns} ||= $cols; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$sub_args{"-columns"} ||= $cols
MC/DC0%0/2
$sub_args{"-columns"} ||= $cols
$sub_args{"-columns"}
$cols
Truth table66%2/3
A ||= B
A= $sub_args{"-columns"}B= $cols
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 16 | ▶ | $sub_args{-from} ||= $from; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$sub_args{"-from"} ||= $from
MC/DC0%0/2
$sub_args{"-from"} ||= $from
$sub_args{"-from"}
$from
Truth table66%2/3
A ||= B
A= $sub_args{"-from"}B= $from
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 16 | local $self->{WITH}; # temporarily disable the WITH part during the recursive call to select() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 16 | my ($sql, @bind) = $self->select(%sub_args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 16 | (my $sql_op = uc($set_op)) =~ s/_/ /g; # for ex. -union_all becomes 'UNION ALL' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 16 | return (" $sql_op $sql", @bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 2 | ▶ | sub _translate_page_into_limit_offset { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_translate_page_into_limit_offset: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 2 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 2 | ▶ | not exists $args->{$_} or puke "-page_size conflicts with $_" for qw/-limit -offset/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 2 | $args->{-limit} = $args->{-page_size}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 2 | ▶ | if ($args->{-page_index}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 2 | $args->{-offset} = ($args->{-page_index} - 1) * $args->{-page_size}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | # insert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 11 | ▶ | sub _setup_insert_inheritance { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_setup_insert_inheritance: called CC=4 SCAR=20.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 11 | my ($parent_sqla) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | # if the parent has method '_expand_insert_value' (SQL::Abstract >= v2.0), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | # we need to override it in this subclass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 11 | ▶ | if ($parent_sqla->can('_expand_insert_value')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | ▶ | *_expand_insert_value = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | my ($self, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | my $k = our $Cur_Col_Meta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | if (ref($v) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | ▶ | if ($self->{array_datatypes} || $self->is_bind_value_with_type($v)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"array_datatypes"} or $self->is_bind_value_with_type($v)
MC/DC0%0/2
$self->{"array_datatypes"} or $self->is_bind_value_with_type($v)
$self->{"array_datatypes"}
$self->is_bind_value_with_type($v)
Truth table0%0/3
A or B
A= $self->{"array_datatypes"}B= $self->is_bind_value_with_type($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | return +{ -bind => [ $k, $v ] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | my ($sql, @bind) = @$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | $self->_assert_bindval_matches_bindtype(@bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | return +{ -literal => $v }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | ▶ | if (ref($v) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | if (grep !/^-/, keys %$v) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | belch "HASH ref as bind value in insert is not supported"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | return +{ -bind => [ $k, $v ] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | if (!defined($v)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | return +{ -bind => [ $k, undef ] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | return $self->expand_expr($v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | # we also need to back-implement the _insert_values method from earlier versions of SQLA | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | *_insert_values = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | my ($sql, @bind) = $self->SUPER::insert(FAKE_TABLE => @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | $sql =~ s/^.*\bVALUES\b/VALUES/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | return ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | # otherwise, if the parent is an old SQL::Abstract or it is SQL::Abstract::Classic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | elsif ($parent_sqla->can('_insert_values')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | # if the parent has no method '_insert_value', this is the old | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | # monolithic _insert_values() method. We must override it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 10 | ▶ | if (!$parent_sqla->can('_insert_value')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 20 | ▶ | *_insert_values = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 20 | my ($self, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 20 | my (@values, @all_bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 20 | foreach my $column (sort keys %$data) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 38 | my ($values, @bind) = $self->_insert_value($column, $data->{$column}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 38 | push @values, $values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 38 | push @all_bind, @bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 20 | my $sql = $self->_sqlcase('values')." ( ".join(", ", @values)." )"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 20 | return ($sql, @all_bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | # now override the _insert_value() method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 38 | ▶ | *_insert_value = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=1.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | # unfortunately, we can't just override the ARRAYREF part, so the whole | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | # parent method is copied here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 38 | my ($self, $column, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 38 | my (@values, @all_bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | $self->_SWITCH_refkind($v, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 2 | ▶ | ARRAYREF => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=15.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 2 | ▶ | if ($self->{array_datatypes} # if array datatype are activated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"array_datatypes"} or $self->is_bind_value_with_type($v)
MC/DC0%0/2
$self->{"array_datatypes"} or $self->is_bind_value_with_type($v)
$self->{"array_datatypes"}
$self->is_bind_value_with_type($v)
Truth table33%1/3
A or B
A= $self->{"array_datatypes"}B= $self->is_bind_value_with_type($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | || $self->is_bind_value_with_type($v)) { # or if this is a bind val | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 2 | push @values, '?'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 2 | push @all_bind, $self->_bindtype($column, $v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | else { # else literal SQL with bind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | my ($sql, @bind) = @$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | $self->_assert_bindval_matches_bindtype(@bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | push @values, $sql; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | push @all_bind, @bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | ▶ | ARRAYREFREF => sub { # literal SQL with bind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | my ($sql, @bind) = @${$v}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | $self->_assert_bindval_matches_bindtype(@bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | push @values, $sql; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | push @all_bind, @bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | # THINK : anything useful to do with a HASHREF ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | ▶ | HASHREF => sub { # (nothing, but old SQLA passed it through) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | #TODO in SQLA >= 2.0 it will die instead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | belch "HASH ref as bind value in insert is not supported"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | push @values, '?'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | push @all_bind, $self->_bindtype($column, $v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | ▶ | SCALARREF => sub { # literal SQL without bind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | push @values, $$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 36 | ▶ | SCALAR_or_UNDEF => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 36 | push @values, '?'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 36 | push @all_bind, $self->_bindtype($column, $v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 38 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 38 | my $sql = CORE::join(", ", @values); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 38 | return ($sql, @all_bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 10 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | puke "unexpected parent class, cannot setup inheritance rules for insert()"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 25 | ▶ | sub insert { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert: called CC=17 SCAR=28.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 25 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 25 | my ($sql, @bind) = (""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 25 | ▶ | my $add_sql_bind = sub {$sql .= shift; push @bind, @_}; # closure for adding to ($sql, @bind) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 25 | ▶ | if (not &_called_with_named_args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 2 | ($sql, @bind) = $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | # extract named args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 23 | my %args = validate(@_, \%params_for_insert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 21 | ▶ | $args{-into} or puke "insert(..) : need -into arg"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 21 | my $source = $self->_parse_datasource($args{-into}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | $add_sql_bind->($self->_sqlcase('insert into') . " " . $source->{sql}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 21 | @{$source->{bind}}, # in principle always empty for an insert, but just for consistency's sake | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 21 | ▶ | if (my $values = $args{-values}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 18 | ▶ | !$args{-select} or puke "insert(-into => .., -values => ...) : incompatible with -select => "; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 18 | ▶ | if (does($values, 'HASH')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 14 | ▶ | !$args{-columns} or puke "insert(-into => .., -values => {...}) : incompatible with -columns => "; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 14 | my $quoted_cols = join ", ", map {$self->_quote($_)} sort keys %$values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 14 | $add_sql_bind->("($quoted_cols)"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | elsif (does($values, 'ARRAY')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 4 | ▶ | if (my $cols = $args{-columns}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 2 | ▶ | $cols = [$cols] if ! ref $cols; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 2 | ▶ | @$cols == @$values or puke "insert(-into => .., -columns => [...], -values => [...]) : numbers of columns do not match"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 2 | my %merged; @merged{@$cols} = @$values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 2 | $values = \%merged; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | # NOTE: in doing so we lost the order of @$cols. In principle this has no impact on the final | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | # result, but nevertheless is not very satisfactory. In a future version when we no longer need | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | # to support SQLA 2.0, we should have our own version of $self->_insert_cols_values($cols, $values); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 2 | my $quoted_cols = join ", ", map {$self->_quote($_)} sort @$cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 2 | $add_sql_bind->("($quoted_cols)"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | # Code and comments below borrowed from SQL::Abstract! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | # fold the list of values into a hash of column name - value pairs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | # (where the column names are artificially generated, and their | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | # lexicographical ordering keep the ordering of the original list) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 2 | my $i = "a"; # incremented values will be in lexicographical order | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 2 | $values = { map { ($i++ => $_) } @$values }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | puke "insert(-into => .., -values => ...) : -values must be a hashref or an arrayref"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 18 | my ($val_sql, @val_bind) = $self->_insert_values($values); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 18 | $add_sql_bind->(" $val_sql", @val_bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | elsif ($args{-select}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 3 | local $self->{WITH}; # temporarily disable the WITH part during the subquery | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 3 | ▶ | if (my $cols = $args{-columns}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 3 | ▶ | $cols = [$cols] if ! ref $cols; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 3 | my $quoted_cols = join ", ", map {$self->_quote($_)} @$cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 3 | $add_sql_bind->("($quoted_cols)"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 3 | my ($select_sql, @select_bind) = $self->select(%{$args{-select}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 3 | $add_sql_bind->(" $select_sql", @select_bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | puke "insert(-into => ..) : need either -values arg or -select arg"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | # THINK: should also support some syntax for generating INSERT INTO Foo(a, b, c) VALUES (1, 2, 3), (4, 5, 6), ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | # Probably a variant like -columns => [qw/a b c/], -values => [[1, 2, 3], [4, 5, 6], ..] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | # deal with -returning arg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 21 | ▶ | if ($args{-returning}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 6 | my ($into, $returning) = $self->_compute_returning($args{-returning}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 6 | my ($r_sql, @r_bind) = $self->_insert_returning($returning); # TODO : implement directly instead of calling SQLA | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 6 | $add_sql_bind->($r_sql, @r_bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | # inject more stuff if using Oracle's "RETURNING ... INTO ..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 6 | ▶ | if ($into) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 2 | $add_sql_bind->($self->_sqlcase(' into ') . join(", ", ("?") x @$into), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | @$into); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | # SQL to add after the INSERT keyword | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 21 | ▶ | $sql =~ s/\b(INSERT)\b/$1 $args{-add_sql}/i if $args{-add_sql}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | # initial WITH clause | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 23 | $self->_prepend_WITH_clause(\$sql, \@bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 23 | return ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | # update | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 11 | ▶ | sub _setup_update_inheritance { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_setup_update_inheritance: called CC=3 SCAR=17.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 11 | my ($parent_sqla) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | # if the parent has method '_expand_update_set_value' (SQL::Abstract >= v2.0), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | # we need to override it in this subclass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 11 | ▶ | if ($parent_sqla->can('_expand_update_set_values')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 1 | *_parent_update = $parent_sqla->can('update'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | ▶ | *_expand_update_set_values = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | my ($self, undef, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | $self->expand_expr({ -list => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | my ($k, $set) = @$_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | ▶ | $set = { -bind => $_ } unless defined $set; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | +{ -op => [ '=', { -ident => $k }, $set ] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 0 | my $k = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | my $v = $data->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | (ref($v) eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | ? ($self->{array_datatypes} || $self->is_bind_value_with_type($v) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | ? [ $k, +{ -bind => [ $k, $v ] } ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | : [ $k, +{ -literal => $v } ]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | ▶ | : do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$self->{"array_datatypes"} or $self->is_bind_value_with_type($v)
MC/DC0%0/2
$self->{"array_datatypes"} or $self->is_bind_value_with_type($v)
$self->{"array_datatypes"}
$self->is_bind_value_with_type($v)
Truth table0%0/3
A or B
A= $self->{"array_datatypes"}B= $self->is_bind_value_with_type($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | local our $Cur_Col_Meta = $k; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | [ $k, $self->_expand_expr($v) ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | } sort keys %$data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | ] }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | # otherwise, if the parent is an old SQL::Abstract or it is SQL::Abstract::Classic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | # if the parent has method '_update_set_values()', it is a SQLA version >=1.85. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | # We can just use its update() method as _parent_update(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 10 | ▶ | if ($parent_sqla->can('_update_set_values')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | *_parent_update = $parent_sqla->can('update'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | # otherwise, it's the old monolithic update() method. We need to supply our own | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | # version as _parent_update(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | ▶ | *_parent_update = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | my $table = $self->_table(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 0 | ▶ | my $data = shift || return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || (return)
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 0 | my $where = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | my $options = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | # first build the 'SET' part of the sql statement | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 0 | ▶ | puke "Unsupported data type specified to \$sql->update" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | unless ref $data eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | my ($sql, @all_bind) = $self->_update_set_values($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | $sql = $self->_sqlcase('update ') . $table . $self->_sqlcase(' set ') | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | . $sql; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | ▶ | if ($where) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | my($where_sql, @where_bind) = $self->where($where); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | $sql .= $where_sql; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 0 | push @all_bind, @where_bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | ▶ | if ($options->{returning}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | my ($returning_sql, @returning_bind) = $self->_update_returning($options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | $sql .= $returning_sql; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | push @all_bind, @returning_bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | ▶ | return wantarray ? ($sql, @all_bind) : $sql; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 6 | ▶ | *_update_returning = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 6 | my ($self, $options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 6 | my $f = $options->{returning}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | my $fieldlist = $self->_SWITCH_refkind($f, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 4 | ▶ | ARRAYREF => sub {join ', ', map { $self->_quote($_) } @$f;}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 2 | ▶ | SCALAR => sub {$self->_quote($f)}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 0 | ▶ | SCALARREF => sub {$$f}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 6 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 6 | return $self->_sqlcase(' returning ') . $fieldlist; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | # now override or supply the _update_set_values() method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 21 | ▶ | *_update_set_values = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=10.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 21 | my ($self, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 21 | my (@set, @all_bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 21 | for my $k (sort keys %$data) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 31 | my $v = $data->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 31 | my $r = ref $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 31 | my $label = $self->_quote($k); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | $self->_SWITCH_refkind($v, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 2 | ▶ | ARRAYREF => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=15.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 2 | ▶ | if ($self->{array_datatypes} # array datatype | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"array_datatypes"} or $self->is_bind_value_with_type($v)
MC/DC0%0/2
$self->{"array_datatypes"} or $self->is_bind_value_with_type($v)
$self->{"array_datatypes"}
$self->is_bind_value_with_type($v)
Truth table33%1/3
A or B
A= $self->{"array_datatypes"}B= $self->is_bind_value_with_type($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | || $self->is_bind_value_with_type($v)) { # or bind value with type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 2 | push @set, "$label = ?"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 2 | push @all_bind, $self->_bindtype($k, $v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | else { # literal SQL with bind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | my ($sql, @bind) = @$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | $self->_assert_bindval_matches_bindtype(@bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 0 | push @set, "$label = $sql"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 0 | push @all_bind, @bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 0 | ▶ | ARRAYREFREF => sub { # literal SQL with bind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 0 | my ($sql, @bind) = @${$v}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 0 | $self->_assert_bindval_matches_bindtype(@bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 0 | push @set, "$label = $sql"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 0 | push @all_bind, @bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 0 | ▶ | SCALARREF => sub { # literal SQL without bind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 0 | push @set, "$label = $$v"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 0 | ▶ | HASHREF => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 0 | my ($op, $arg, @rest) = %$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 0 | ▶ | puke 'Operator calls in update must be in the form { -op => $arg }' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@rest or not $op =~ /^\-(.+)/
MC/DC0%0/2
@rest or not $op =~ /^\-(.+)/
@rest
not $op =~ /^\-(.+)/
Truth table0%0/3
A or not(B)
A= @restB= not $op =~ /^\-(.+)/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | if (@rest or not $op =~ /^\-(.+)/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 0 | local $self->{_nested_func_lhs} = $k; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 0 | my ($sql, @bind) = $self->_where_unary_op($1, $arg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 0 | push @set, "$label = $sql"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 0 | push @all_bind, @bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 29 | ▶ | SCALAR_or_UNDEF => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 29 | push @set, "$label = ?"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 29 | push @all_bind, $self->_bindtype($k, $v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 31 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | # generate sql | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 21 | my $sql = CORE::join ', ', @set; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 21 | return ($sql, @all_bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 23 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 23 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 23 | my ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 23 | ▶ | if (not &_called_with_named_args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 2 | ($sql, @bind) = $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 21 | my %args = validate(@_, \%params_for_update); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | # first build the 'SET' part of the sql statement | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 21 | ▶ | does($args{-set}, 'HASH') or puke "Unsupported data type specified to \$sql->update"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 21 | ($sql, @bind) = $self->_update_set_values($args{-set}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | # add the initial part of the statement | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 21 | my $join_info = $self->_compute_join_info($args{-table}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | my $table = defined $join_info ? $join_info->{sql} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 21 | ▶ | : $self->_parse_table($args{-table})->{sql}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 21 | substr($sql, 0, 0) = $self->_sqlcase('update ') . $table . $self->_sqlcase(' set '); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | # add the 'WHERE' part | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 21 | ▶ | if ($args{-where}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 9 | my ($where_sql, @where_bind) = $self->where($args{-where}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 9 | $sql .= $where_sql; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 9 | push @bind, @where_bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | # deal with -returning arg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 21 | my ($into, $returning) = $self->_compute_returning($args{-returning}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 21 | ▶ | $sql .= $self->_update_returning($returning) if $returning; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | # merge with bind values from $join_info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 21 | ▶ | unshift @bind, @{$join_info->{bind}} if $join_info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | # handle additional args if needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 21 | $self->_handle_additional_args_for_update_delete(\%args, \$sql, \@bind, qr/UPDATE/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | # deal with Oracle's "RETURNING ... INTO ..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 21 | ▶ | if ($into) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 2 | $sql .= ' INTO ' . join(", ", ("?") x @$into); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 2 | push @bind, @$into; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | # initial WITH clause | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 23 | $self->_prepend_WITH_clause(\$sql, \@bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 23 | return ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | # delete | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 11 | ▶ | sub delete { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 11 | my ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 11 | ▶ | if (not &_called_with_named_args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | 2 | ($sql, @bind) = $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 9 | my %args = validate(@_, \%params_for_delete); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 9 | ($sql, @bind) = $self->where($args{-where}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 9 | substr($sql, 0, 0) = $self->_sqlcase('delete from ') . $self->_parse_table($args{-from})->{sql}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | # handle additional args if needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 9 | $self->_handle_additional_args_for_update_delete(\%args, \$sql, \@bind, qr/DELETE/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | # initial WITH clause | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 11 | $self->_prepend_WITH_clause(\$sql, \@bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 11 | return ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | # auxiliary methods for insert(), update() and delete() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 27 | ▶ | sub _compute_returning { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compute_returning: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 27 | my ($self, $arg_returning) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 27 | my ($returning_into, $old_API_options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | 27 | ▶ | if ($arg_returning) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | # if present, "-returning" may be a scalar, arrayref or hashref; the latter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | # is interpreted as .. RETURNING ... INTO ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | 12 | ▶ | if (does $arg_returning, 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 4 | ▶ | my @keys = sort keys %$arg_returning | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | or puke "-returning => {} : the hash is empty"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 4 | $old_API_options = {returning => \@keys}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 4 | $returning_into = [@{$arg_returning}{@keys}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | 8 | $old_API_options = {returning => $arg_returning}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | 27 | return ($returning_into, $old_API_options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | 30 | ▶ | sub _handle_additional_args_for_update_delete { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_additional_args_for_update_delete: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 30 | my ($self, $args, $sql_ref, $bind_ref, $keyword_regex) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 30 | ▶ | if (defined $args->{-order_by}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 4 | my ($sql_ob, @bind_ob) = $self->_order_by($args->{-order_by}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 4 | $$sql_ref .= $sql_ob; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 4 | push @$bind_ref, @bind_ob; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 30 | ▶ | if (defined $args->{-limit}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | # can't call $self->limit_offset(..) because there shouldn't be any offset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 4 | $$sql_ref .= $self->_sqlcase(' limit ?'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 4 | push @$bind_ref, $args->{-limit}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | 30 | ▶ | if (defined $args->{-add_sql}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | 4 | $$sql_ref =~ s/\b($keyword_regex)\b/$1 $args->{-add_sql}/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | 71 | ▶ | sub _order_by { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_order_by: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 71 | my ($self, $order) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | # force scalar into an arrayref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 71 | ▶ | $order = [$order] if not ref $order; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | # restructure array data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 71 | ▶ | if (does $order, 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 59 | my @clone = @$order; # because we will modify items | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | # '-' and '+' prefixes are translated into {-desc/asc => } hashrefs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | 59 | foreach my $item (@clone) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | 89 | ▶ | next if !$item or ref $item; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $item or ref $item
MC/DC100%2/2
not $item or ref $item
not $item
ref $item
Truth table100%3/3
not(A) or B
A= not $itemB= ref $item
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 55 | ▶ | $item =~ s/^-// and $item = {-desc => $item} and next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$item =~ s/^-// and $item = {"-desc", $item}
MC/DC100%1/1
$item =~ s/^-// and $item = {"-desc", $item}
$item =~ s/^-//
Truth table100%2/2
A
A= $item =~ s/^-//
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | 51 | ▶ | $item =~ s/^\+// and $item = {-asc => $item}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 59 | $order = \@clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 71 | return $self->next::method($order); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | # other public methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | # same pattern for 3 invocation methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 45 | ▶ | sub table_alias {my $self = shift; my $meth = $self->{table_alias}; $self->$meth(@_)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table_alias: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 64 | ▶ | sub column_alias {my $self = shift; my $meth = $self->{column_alias}; $self->$meth(@_)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
column_alias: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 18 | ▶ | sub limit_offset {my $self = shift; my $meth = $self->{limit_offset}; $self->$meth(@_)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
limit_offset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | # readonly accessor methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 11 | foreach my $key (qw/join_syntax join_assoc_right | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | max_members_IN multicols_sep has_multicols_in_SQL/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 11 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | 2 | ▶ | *{$key} = sub {shift->{$key}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | # invocation method for 'join' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 47 | ▶ | sub join { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
join: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 47 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | # start from the right if right-associative | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | 47 | ▶ | @_ = reverse @_ if $self->{join_assoc_right}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | # shift first single item (a table) before reducing pairs (op, table) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 47 | my $first_source = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 47 | my $accumulator = $self->_parse_datasource($first_source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | # reduce pairs (op, table) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 47 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | # shift 2 items : next join specification and next table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 54 | my $join_spec = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 54 | ▶ | my $next_source = shift or puke "->join(): improper number of operands"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 54 | ▶ | $join_spec = $self->_parse_join_spec($join_spec) unless ref $join_spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 54 | $next_source = $self->_parse_datasource($next_source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 54 | $accumulator = $self->_single_join($accumulator, $join_spec, $next_source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 46 | return $accumulator; # {sql=> .., bind => [..], aliased_tables => {..}} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | # utility for merging several "where" clauses | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 2 | ▶ | sub merge_conditions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
merge_conditions: called CC=8 SCAR=26.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | 2 | my %merged; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 2 | foreach my $cond (@_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 4 | ▶ | if (does $cond, 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | 4 | foreach my $col (sort keys %$cond) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | $merged{$col} = $merged{$col} ? [-and => $merged{$col}, $cond->{$col}] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | 8 | ▶ | : $cond->{$col}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | elsif (does $cond, 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | 0 | ▶ | $merged{-nest} = $merged{-nest} ? {-and => [$merged{-nest}, $cond]} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | : $cond; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | elsif ($cond) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | 0 | $merged{$cond} = \""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | 2 | return \%merged; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | # utility for calling either bind_param or bind_param_inout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | 11 | our $INOUT_MAX_LEN = 99; # chosen arbitrarily; see L<DBI/bind_param_inout> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | 0 | ▶ | sub bind_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind_params: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 0 | my ($self, $sth, @bind) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 0 | ▶ | $sth->isa('DBI::st') or puke "sth argument is not a DBI statement handle"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | 0 | foreach my $i (0 .. $#bind) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | 0 | my $val = $bind[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | 0 | ▶ | if (does $val, 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | # a scalarref is interpreted as an INOUT parameter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | 0 | $sth->bind_param_inout($i+1, $val, $INOUT_MAX_LEN); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | ▶ | elsif (does $val, 'ARRAY' and | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
&does($val, "ARRAY") and () = $self->is_bind_value_with_type($val)
MC/DC0%0/2
&does($val, "ARRAY") and () = $self->is_bind_value_with_type($val)
&does($val, "ARRAY")
() = $self->is_bind_value_with_type($val)
Truth table0%0/3
A and B
A= &does($val, "ARRAY")B= () = $self->is_bind_value_with_type($val)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | my ($bind_meth, @args) = $self->is_bind_value_with_type($val)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | # either 'bind_param' or 'bind_param_inout', with 2 or 3 args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 0 | $sth->$bind_meth($i+1, @args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | # other cases are passed directly to DBI::bind_param | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | 0 | $sth->bind_param($i+1, $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | 18 | ▶ | sub is_bind_value_with_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_bind_value_with_type: called CC=6 SCAR=19.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | 18 | my ($self, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | # compatibility with DBIx::Class syntax of shape [\%args => $val], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | # see L<DBIx::Class::ResultSet/"DBIC BIND VALUES"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 18 | ▶ | if ( @$val == 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
@$val == 2 and &does($val->[0], "HASH") and grep {$val->[0]{$_};} "dbd_attrs", "sqlt_size", "sqlt_datatype", "dbic_colname"
@$val == 2 and &does($val->[0], "HASH")
MC/DC66%2/3
@$val == 2 and &does($val->[0], "HASH") and grep {$val->[0]{$_};} "dbd_attrs", "sqlt_size", "sqlt_datatype", "dbic_colname"
@$val == 2
&does($val->[0], "HASH")
grep {$val->[0]{$_};} "dbd_attrs", "sqlt_size", "sqlt_datatype", "dbic_colname"
Truth table75%3/4
A and B and C
A= @$val == 2B= &does($val->[0], "HASH")C= grep {$val->[0]{$_};} "dbd_attrs", "sqlt_size", "sqlt_datatype", "dbic_colname"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | && does($val->[0], 'HASH') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | 40 | && grep {$val->[0]{$_}} qw/dbd_attrs sqlt_size | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | sqlt_datatype dbic_colname/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | 8 | my $args = $val->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 8 | ▶ | if (my $attrs = $args->{dbd_attrs}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | 8 | return (bind_param => $val->[1], $attrs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | elsif (my $size = $args->{sqlt_size}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 0 | return (bind_param_inout => $val, $size); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | # other options like 'sqlt_datatype', 'dbic_colname' are not supported | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 0 | puke "unsupported options for bind type : " . CORE::join(", ", sort keys %$args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | # NOTE : the following DBIx::Class shortcuts are not supported | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | # [ $name => $val ] === [ { dbic_colname => $name }, $val ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | # [ \$dt => $val ] === [ { sqlt_datatype => $dt }, $val ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | # [ undef, $val ] === [ {}, $val ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | # in all other cases, this is not a bind value with type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | 10 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | # private utility methods for 'join' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | 279 | ▶ | sub _compute_join_info { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compute_join_info: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | 279 | my ($self, $table_arg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | 279 | ▶ | if (does($table_arg, 'ARRAY') && $table_arg->[0] eq '-join') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
&does($table_arg, "ARRAY") and $table_arg->[0] eq "-join"
MC/DC100%2/2
&does($table_arg, "ARRAY") and $table_arg->[0] eq "-join"
&does($table_arg, "ARRAY")
$table_arg->[0] eq "-join"
Truth table100%3/3
A and B
A= &does($table_arg, "ARRAY")B= $table_arg->[0] eq "-join"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 22 | return $self->join(@{$table_arg}[1 .. $#$table_arg]); # drop initial '-join' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 257 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | 475 | ▶ | sub _parse_alias { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_alias: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | 475 | my ($self, $input_sql) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | 475 | ▶ | return $input_sql =~ /^\s* # ignore insignificant leading spaces | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | (\S.*?) # $1: any non-empty string, no starting with space (but may include '|') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | (?<!\|) # no final '|' in the previous string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | \| # literal '|' (the last in the string) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | (\pL[\w\s]*?) # $2 : alias name: initial letter, then word chars or spaces | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | $/x | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | # sql alias | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | # === ===== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | ? ($1, $2 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | : ($input_sql, undef); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | 258 | ▶ | sub _parse_datasource { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_datasource: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | 258 | my ($self, $source) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | 258 | ▶ | if (my $join_info = $self->_compute_join_info($source)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | 20 | return $join_info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | elsif (_is_subquery($source)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | # separate the $sql and @bind parts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | 8 | my ($sql, @bind) = @$$source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | 8 | my $table_spec = $self->_parse_table(_parenthesize_select($sql), -dont_quote_table); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | 8 | $table_spec->{bind} = \@bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | 8 | return $table_spec; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | elsif (does($source, 'ARRAY')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | # compatibility with old SQL::Abstract -- deprecated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | 4 | my @table_specs = map {$self->_parse_table($_)} @$source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | 8 | return {sql => (CORE::join ', ', map {$_->{sql}} @table_specs), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | 8 | bind => [ map {@{$_->{bind}}} @table_specs], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | 4 | aliased_tables => { map {%{$_->{aliased_tables}}} @table_specs}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | elsif (does($source, 'SCALAR')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | # reference to a SQL string --> handled as is without quoting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | 2 | return $self->_parse_table($$source, -dont_quote_table); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | 224 | return $self->_parse_table($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | 270 | ▶ | sub _parse_table { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_table: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | 270 | my ($self, $table, $dont_quote_table) = @_; # $dont_quote_table: just a boolean | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | 270 | ($table, my $alias) = $self->_parse_alias($table); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | 270 | ▶ | my $table_spec = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$alias || $table
MC/DC0%0/2
$alias || $table
$alias
$table
Truth table66%2/3
A || B
A= $aliasB= $table
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | bind => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | name => ($alias || $table), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | aliased_tables => {$alias ? ($alias => $table) : ()}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | 270 | ▶ | $table = $self->_quote($table) unless $dont_quote_table; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | 270 | ▶ | $table_spec->{sql} = $alias ? $self->table_alias($table, $self->_quote($alias)) : $table; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | 270 | return $table_spec; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | 49 | ▶ | sub _parse_join_spec { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_join_spec: called CC=19 SCAR=29.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | 49 | my ($self, $join_spec) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | # parse the join specification | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | 49 | ▶ | $join_spec | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | or puke "empty join specification"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | my ($op, $bracket, $cond_list) = ($join_spec =~ $self->{join_regex}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | 49 | ▶ | or puke "incorrect join specification : $join_spec\n$self->{join_regex}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | 49 | ▶ | $op ||= '<=>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$op ||= "<=>"
MC/DC100%1/1
$op ||= "<=>"
$op
Truth table100%2/2
A
A= $op
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | 49 | ▶ | $bracket ||= '{'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$bracket ||= "{"
MC/DC100%1/1
$bracket ||= "{"
$bracket
Truth table100%2/2
A
A= $bracket
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | 49 | ▶ | $cond_list ||= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$cond_list ||= ""
MC/DC100%1/1
$cond_list ||= ""
$cond_list
Truth table100%2/2
A
A= $cond_list
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | # extract constants (strings between quotes), replaced by placeholders | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | 49 | my $regex = qr/' # initial quote | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | ( # begin capturing group | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | [^']* # any non-quote chars | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | (?: # begin non-capturing group | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | '' # pair of quotes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | [^']* # any non-quote chars | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | )* # this non-capturing group 0 or more times | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | ) # end of capturing group | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | ' # ending quote | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | /x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | 49 | my $placeholder = '_?_'; # unlikely to be counfounded with any value | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | 49 | my @constants; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | 49 | ▶ | while ($cond_list =~ s/$regex/$placeholder/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | 8 | push @constants, $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | 49 | s/''/'/g for @constants; # replace pairs of quotes by single quotes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | # accumulate conditions as pairs ($left => \"$op $right") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | 49 | my @conditions; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | my @using; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | 49 | foreach my $cond (split /,\s*/, $cond_list) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | # parse the condition (left and right operands + comparison operator) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | 64 | my ($left, $cmp, $right) = split /([<>=!^]{1,2})/, $cond; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | 64 | ▶ | if ($cmp && $right) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$cmp and $right
MC/DC50%1/2
$cmp and $right
$cmp
$right
Truth table66%2/3
A and B
A= $cmpB= $right
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | # if operands are not qualified by table/alias name, add sprintf hooks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | 56 | ▶ | $left = '%1$s.' . $left unless $left =~ /\./; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | 56 | ▶ | $right = '%2$s.' . $right unless $right =~ /\./ or $right eq $placeholder; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$right =~ /\./ or $right eq $placeholder
MC/DC100%2/2
$right =~ /\./ or $right eq $placeholder
$right =~ /\./
$right eq $placeholder
Truth table100%3/3
A or B
A= $right =~ /\./B= $right eq $placeholder
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | # add this pair into the list; right operand is either a bind value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | # or an identifier within the right table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | 56 | ▶ | $right = $right eq $placeholder ? shift @constants : {-ident => $right}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | 56 | push @conditions, $left, {$cmp => $right}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | elsif ($cond =~ /^\w+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | 8 | push @using, $cond; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | 0 | else {puke "can't parse join condition: $cond"} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | # build join hashref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | 49 | my $join_hash = {operator => $op}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | 49 | ▶ | $join_hash->{using} = \@using if @using; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | $join_hash->{condition} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | 49 | ▶ | = $bracket eq '[' ? [@conditions] : {@conditions} if @conditions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | 49 | return $join_hash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | 54 | ▶ | sub _single_join { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_single_join: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | 54 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | # if right-associative, restore proper left-right order in pair | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | 54 | ▶ | @_ = reverse @_ if $self->{join_assoc_right}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | 54 | my ($left, $join_spec, $right) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | # syntax for assembling all elements | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | 54 | my $syntax = $self->{join_syntax}{$join_spec->{operator}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | 54 | my ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | 11 | ▶ | { no if $] ge '5.022000', warnings => 'redundant'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | # because sprintf instructions may _intentionally_ omit %.. parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | 54 | ▶ | if ($join_spec->{using}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | not $join_spec->{condition} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | 11 | ▶ | or puke "join specification has both {condition} and {using} fields"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | 10 | $syntax =~ s/\bON\s+%s/USING (%s)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | 10 | $sql = CORE::join ",", map {$self->_quote($_)} @{$join_spec->{using}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | elsif ($join_spec->{condition}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | not $join_spec->{using} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | 41 | ▶ | or puke "join specification has both {condition} and {using} fields"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | # compute the "ON" clause | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | 41 | ($sql, @bind) = $self->where($join_spec->{condition}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | 41 | $sql =~ s/^\s*WHERE\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | # substitute left/right tables names for '%1$s', '%2$s' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | 41 | $sql = sprintf $sql, $left->{name}, $right->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | # build the final sql | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | 53 | $sql = sprintf $syntax, $left->{sql}, $right->{sql}, $sql; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | # add left/right bind parameters (if any) into the list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | 53 | unshift @bind, @{$left->{bind}}, @{$right->{bind}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | # build result and return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | 53 | my %result = (sql => $sql, bind => \@bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | 53 | ▶ | $result{name} = ($self->{join_assoc_right} ? $left : $right)->{name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | 53 | $result{aliased_tables} = $left->{aliased_tables}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | 53 | foreach my $alias (keys %{$right->{aliased_tables}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | 14 | $result{aliased_tables}{$alias} = $right->{aliased_tables}{$alias}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | 53 | return \%result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | # override of parent's "_where_field_IN" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | 54 | ▶ | sub _where_field_IN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_where_field_IN: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | 54 | my ($self, $k, $op, $vals) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | # special algorithm if the key is multi-columns (contains a multicols_sep) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | 54 | ▶ | if ($self->{multicols_sep}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | 8 | my @cols = split m[$self->{multicols_sep}], $k; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | 8 | ▶ | if (@cols > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | 8 | ▶ | if ($self->{has_multicols_in_SQL}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | # DBMS accepts special SQL syntax for multicolumns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | 6 | return $self->_multicols_IN_through_SQL(\@cols, $op, $vals); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | # DBMS doesn't accept special syntax, so we must use boolean logic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | 2 | return $self->_multicols_IN_through_boolean(\@cols, $op, $vals); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | # special algorithm if the number of values exceeds the allowed maximum | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | 46 | my $max_members_IN = $self->{max_members_IN}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | 46 | ▶ | if ($max_members_IN && does($vals, 'ARRAY') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$max_members_IN and &does($vals, "ARRAY") and @$vals > $max_members_IN
$max_members_IN and &does($vals, "ARRAY")
MC/DC100%3/3
$max_members_IN and &does($vals, "ARRAY") and @$vals > $max_members_IN
$max_members_IN
&does($vals, "ARRAY")
@$vals > $max_members_IN
Truth table100%4/4
A and B and C
A= $max_members_INB= &does($vals, "ARRAY")C= @$vals > $max_members_IN
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | && @$vals > $max_members_IN) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | 8 | my @vals = @$vals; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | 8 | my @slices; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | 8 | ▶ | while (my @slice = splice(@vals, 0, $max_members_IN)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | 24 | push @slices, \@slice; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | 8 | my @clauses = map {{-$op, $_}} @slices; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | 8 | ▶ | my $connector = $op =~ /^not/i ? '-and' : '-or'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | 8 | unshift @clauses, $connector; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | 8 | my ($sql, @bind) = $self->where({$k => \@clauses}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | 8 | $sql =~ s/\s*where\s*\((.*)\)/$1/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | 8 | return ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | # otherwise, call parent method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | 38 | ▶ | $vals = [@$vals] if blessed $vals; # because SQLA dies on blessed arrayrefs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | 38 | return $self->next::method($k, $op, $vals); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | 6 | ▶ | sub _multicols_IN_through_SQL { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_multicols_IN_through_SQL: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | 6 | my ($self, $cols, $op, $vals) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | # build initial sql | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | 6 | my $n_cols = @$cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | 6 | my $sql_cols = CORE::join(',', map {$self->_quote($_)} @$cols); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | 6 | my $sql = "($sql_cols) " . $self->_sqlcase($op); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | # dispatch according to structure of $vals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1420 | return $self->_SWITCH_refkind($vals, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1422 | 4 | ▶ | ARRAYREF => sub { # list of tuples | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=19.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1423 | # deal with special case of empty list (like the parent class) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1424 | 4 | my $n_tuples = @$vals; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1425 | 4 | ▶ | if (!$n_tuples) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1426 | 0 | ▶ | my $sql = ($op =~ /\bnot\b/i) ? $self->{sqltrue} : $self->{sqlfalse}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1427 | 0 | return ($sql); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | # otherwise, build SQL and bind values for the list of tuples | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | 4 | my @bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | 4 | foreach my $val (@$vals) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | 6 | ▶ | does($val, 'ARRAY') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1434 | or $val = [split m[$self->{multicols_sep}], $val]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1435 | 6 | ▶ | @$val == $n_cols | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1436 | or puke "op '$op' with multicols: tuple with improper number of cols"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | 6 | push @bind, @$val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | 4 | my $single_tuple = "(" . CORE::join(',', (('?') x $n_cols)) . ")"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1441 | 4 | my $all_tuples = CORE::join(', ', (($single_tuple) x $n_tuples)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1442 | 4 | $sql .= " ($all_tuples)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1443 | 4 | return ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1444 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1446 | 1 | ▶ | SCALARREF => sub { # literal SQL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | 1 | $sql .= " ($$vals)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | 1 | return ($sql); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | 1 | ▶ | ARRAYREFREF => sub { # literal SQL with bind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | 1 | my ($inner_sql, @bind) = @$$vals; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1453 | 1 | $sql .= " ($inner_sql)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1454 | 1 | return ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1455 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1457 | 0 | ▶ | FALLBACK => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1458 | 0 | puke "op '$op' with multicols requires a list of tuples or literal SQL"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1459 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1461 | 6 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1462 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1464 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1465 | 2 | ▶ | sub _multicols_IN_through_boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_multicols_IN_through_boolean: called CC=7 SCAR=20.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1466 | 2 | my ($self, $cols, $op, $vals) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1468 | # can't handle anything else than a list of tuples | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1469 | 2 | ▶ | does($vals, 'ARRAY') && @$vals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
&does($vals, "ARRAY") and @$vals
MC/DC0%0/2
&does($vals, "ARRAY") and @$vals
&does($vals, "ARRAY")
@$vals
Truth table33%1/3
A and B
A= &does($vals, "ARRAY")B= @$vals
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1470 | or puke "op '$op' with multicols requires a non-empty list of tuples"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1472 | # assemble SQL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1473 | 2 | my $n_cols = @$cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1474 | 2 | my $sql_cols = CORE::join(' AND ', map {$self->_quote($_) . " = ?"} @$cols); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1475 | 2 | my $sql = "(" . CORE::join(' OR ', (("($sql_cols)") x @$vals)) . ")"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1476 | 2 | ▶ | $sql = "NOT $sql" if $op =~ /\bnot\b/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1478 | # assemble bind values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1479 | 2 | my @bind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1480 | 2 | foreach my $val (@$vals) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1481 | 3 | ▶ | does($val, 'ARRAY') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1482 | or $val = [split m[$self->{multicols_sep}], $val]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1483 | 3 | ▶ | @$val == $n_cols | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1484 | or puke "op '$op' with multicols: tuple with improper number of cols"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1485 | 3 | push @bind, @$val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1486 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1487 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1488 | # return the whole thing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1489 | 2 | return ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1490 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1491 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1494 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1495 | # override parent's methods for decoding arrayrefs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1496 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1498 | 12 | ▶ | sub _where_hashpair_ARRAYREF { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_where_hashpair_ARRAYREF: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1499 | 12 | my ($self, $k, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1500 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1501 | 12 | ▶ | if ($self->is_bind_value_with_type($v)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1502 | 2 | $self->_assert_no_bindtype_columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1503 | my $sql = CORE::join ' ', $self->_convert($self->_quote($k)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1504 | 2 | $self->_sqlcase($self->{cmp}), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1505 | $self->_convert('?'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1506 | 2 | my @bind = ($v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1507 | 2 | return ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1508 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1509 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1510 | 10 | return $self->next::method($k, $v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1511 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1512 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1513 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1514 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1515 | 2 | ▶ | sub _where_field_op_ARRAYREF { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_where_field_op_ARRAYREF: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1516 | 2 | my ($self, $k, $op, $vals) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1518 | 2 | ▶ | if ($self->is_bind_value_with_type($vals)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1519 | 2 | $self->_assert_no_bindtype_columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1520 | 2 | my $sql = CORE::join ' ', $self->_convert($self->_quote($k)), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1521 | $self->_sqlcase($op), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1522 | $self->_convert('?'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1523 | 2 | my @bind = ($vals); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1524 | 2 | return ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1525 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1526 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1527 | 0 | return $self->next::method($k, $op, $vals); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1529 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1530 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1531 | 4 | ▶ | sub _assert_no_bindtype_columns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_no_bindtype_columns: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1532 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1533 | 4 | ▶ | $self->{bindtype} ne 'columns' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1534 | or puke 'values of shape [$val, \%type] are not compatible' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1535 | . 'with ...->new(bindtype => "columns")'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1536 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1537 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1539 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1540 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1541 | # method creations through closures | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1542 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1543 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1544 | 56 | ▶ | sub _make_aliasing_sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_aliasing_sub: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1545 | 56 | my ($self, $syntax_field) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1546 | 56 | my $syntax = $self->{$syntax_field}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1547 | 109 | ▶ | $self->{$syntax_field} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1548 | 109 | my ($self, $name, $alias) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1549 | 109 | ▶ | return $alias ? sprintf($syntax, $name, $alias) : $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1550 | 56 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1552 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1553 | 26 | ▶ | sub _choose_LIMIT_OFFSET_dialect { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_choose_LIMIT_OFFSET_dialect: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1554 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1555 | 26 | my $dialect = $self->{limit_offset}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1556 | 26 | ▶ | my $method = $limit_offset_dialects{$dialect} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1557 | or puke "no such limit_offset dialect: $dialect"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1558 | 26 | $self->{limit_offset} = $method; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1559 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1560 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1561 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1562 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1563 | # utility functions (not methods) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1564 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1566 | 199 | ▶ | sub _called_with_named_args { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_called_with_named_args: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1567 | 199 | ▶ | return $_[0] && !ref $_[0] && substr($_[0], 0, 1) eq '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$_[0] && !ref($_[0]) && substr($_[0], 0, 1) eq '-'
$_[0] and not ref $_[0]
MC/DC33%1/3
$_[0] && !ref($_[0]) && substr($_[0], 0, 1) eq '-'
$_[0]
not ref $_[0]
substr($_[0], 0, 1) eq '-'
Truth table50%2/4
A and not(B) && C
A= $_[0]B= not ref $_[0]C= substr($_[0], 0, 1) eq '-'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1568 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1569 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1570 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1571 | 443 | ▶ | sub _is_subquery { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_subquery: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1572 | 443 | my $arg = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1573 | 443 | ▶ | return does($arg, 'REF') && does($$arg, 'ARRAY'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
&does($arg, 'REF') && &does($$arg, 'ARRAY')
MC/DC50%1/2
&does($arg, 'REF') && &does($$arg, 'ARRAY')
&does($arg, 'REF')
&does($$arg, 'ARRAY')
Truth table66%2/3
A && B
A= &does($arg, 'REF')B= &does($$arg, 'ARRAY')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1574 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1575 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1576 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1577 | 14 | ▶ | sub _parenthesize_select { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parenthesize_select: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1578 | 14 | my ($sql) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1579 | 14 | $sql =~ s{^(select\b.*)}{($1)}is; # if subquery is a plain SELECT, put it in parenthesis | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1580 | 14 | return $sql; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1581 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1582 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1583 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1584 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1586 | 11 | 1; # End of SQL::Abstract::More | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1588 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||