| 1 | 29 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package DBIx::Squirrel::st; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 29 | ▶ | use DBI qw(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 29 | ▶ | use List::Util qw(max pairs); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 29 | ▶ | use Ref::Util qw(is_coderef is_plain_arrayref is_plain_hashref is_ref); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 29 | ▶ | use DBIx::Squirrel::Errors qw(at_caller croakf); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 29 | ▶ | use DBIx::Squirrel::Iterator qw(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 29 | ▶ | use DBIx::Squirrel::Placeholders qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | is_numbered key_of place_values values_taken | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 29 | ); | |||||||||||||||||||||||||||||||||||||||||
| 14 | 29 | ▶ | use DBIx::Squirrel::Results qw(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 29 | ▶ | use Ekorn::Pipeline::Pipes qw(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 29 | ▶ | use DBIx::Squirrel::Util qw(unwrap_values); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 29 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 29 | our @ISA = ('DBI::st', 'Ekorn::Pipeline::Pipes'); | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | # Croak at the line that called DBIx::Squirrel. | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 29 | our @CARP_NOT = @DBIx::Squirrel::Errors::INTERNAL; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # Bind values to the statement's placeholders, without executing it, and | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # return the handle, or nothing if the DBI couldn't bind one. Numbered | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # placeholders take values in order, the first to every use of 1, and so | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # on; named ones take a hash reference or a list of names and values. An | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # array reference stands for the values in it. | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 69 | ▶ | sub bind ($self, @args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 69 | return _bind($self, _binds($self), _unwrap($self, @args)); | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | # Bind values, as bind does, given as a list, and the statement's map of | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # placeholders to positions, if it has one. Each value is bound to its | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # positions directly, with the DBI's bind_param. | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 69 | ▶ | sub _bind ($self, $binds, @args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bind: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 69 | my @placed; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 69 | ▶ | if ($binds) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 64 | my $given = DBIx::Squirrel::Placeholders::_values_for($binds, \@args); ## no critic (Subroutines::ProtectPrivateSubs) | |||||||||||||||||||||||||||||||||||||||||
| 41 | 61 | my $state = $self->{private_ekorn}; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 61 | @placed = @{ DBIx::Squirrel::Placeholders::_place_values($state, $given) }; ## no critic (Subroutines::ProtectPrivateSubs) | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 5 | @placed = map { ($_ => $args[$_ - 1]) } 1 .. @args; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 66 | ▶ | return at_caller { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 66 | for my $pair (pairs @placed) { | |||||||||||||||||||||||||||||||||||||||||
| 49 | 111 | ▶ | $self->SUPER::bind_param(@$pair) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 65 | ▶ | $self->{private_ekorn}{AllBound} = 1 if $binds; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 65 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 66 | }; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | # Bind a value to a placeholder, as the DBI's bind_param does, given its | ||||||||||||||||||||||||||||||||||||||||||
| 57 | # number or its name, with or without the sigil, and bind it to every use | ||||||||||||||||||||||||||||||||||||||||||
| 58 | # of that placeholder in the statement; for a list placeholder, bind each | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # value in the list to a position of its own. Return what the DBI returns. | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 18 | ▶ | sub bind_param ($self, $param, $value, @attrs) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind_param: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | my $binds = _binds($self) | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 18 | ▶ | or return at_caller { $self->SUPER::bind_param($param, $value, @attrs) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 16 | my $key = key_of($param); | |||||||||||||||||||||||||||||||||||||||||
| 64 | 16 | ▶ | unless ($binds->{$key}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | # A position, for a statement with named placeholders. | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 6 | ▶ | if ($param =~ m( \A \d+ \z )xa && !is_numbered($binds)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$param =~ / \A \d+ \z /ax and not is_numbered($binds)
MC/DC100%2/2
$param =~ / \A \d+ \z /ax and not is_numbered($binds)
$param =~ / \A \d+ \z /ax
not is_numbered($binds)
Truth table100%3/3
A and not(B)
A= $param =~ / \A \d+ \z /axB= not is_numbered($binds)
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | ▶ | my $rv = at_caller { $self->SUPER::bind_param($param, $value, @attrs) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | ▶ | $self->{private_ekorn}{Bound}{$param} = 1 if $rv; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 3 | return $rv; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 3 | croakf 'Expected a placeholder of the statement (%s)', $param; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 10 | my @placed = pairs place_values($self->{private_ekorn}, $key => $value); | |||||||||||||||||||||||||||||||||||||||||
| 75 | 9 | my $rv; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 9 | for my $pair (@placed) { | |||||||||||||||||||||||||||||||||||||||||
| 77 | 16 | ▶ | $rv = at_caller { $self->SUPER::bind_param(@$pair, @attrs) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 16 | ▶ | or return $rv; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 9 | $self->{private_ekorn}{Bound}{$_->[0]} = 1 for @placed; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 9 | return $rv; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | # Execute the statement, as the DBI's execute does, with any values given | ||||||||||||||||||||||||||||||||||||||||||
| 85 | # bound as bind binds them. Values for numbered or named placeholders go | ||||||||||||||||||||||||||||||||||||||||||
| 86 | # to the DBI's execute in the order of their positions, which binds them | ||||||||||||||||||||||||||||||||||||||||||
| 87 | # as bind_param would, in one call. With the ekorn_finish_active | ||||||||||||||||||||||||||||||||||||||||||
| 88 | # attribute, a statement still active from an earlier execute is finished | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # first. While execute_for_fetch runs, values come by position already, a | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # value for each use of each placeholder, and go to the DBI as they are. | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 1977 | ▶ | sub execute ($self, @args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 1977 | my $state = $self->{private_ekorn}; | |||||||||||||||||||||||||||||||||||||||||
| 93 | $self->finish | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 1977 | ▶ | if $state && $state->{Options}{ekorn_finish_active} && $self->{Active}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$state and $state->{"Options"}{"ekorn_finish_active"} and $self->{"Active"}
$state and $state->{"Options"}{"ekorn_finish_active"}
MC/DC66%2/3
$state and $state->{"Options"}{"ekorn_finish_active"} and $self->{"Active"}
$state
$state->{"Options"}{"ekorn_finish_active"}
$self->{"Active"}
Truth table75%3/4
A and B and C
A= $stateB= $state->{"Options"}{"ekorn_finish_active"}C= $self->{"Active"}
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | # Only values in an array reference given alone need unwrapping, and | ||||||||||||||||||||||||||||||||||||||||||
| 96 | # most aren't: the call, copying them in and out, is left out for | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # them (roadmap 2026-0028). | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 1977 | ▶ | @args = _unwrap($self, @args) if @args == 1 && is_plain_arrayref($args[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@args == 1 and Ref::Util::XS::is_plain_arrayref($args[0])
MC/DC100%2/2
@args == 1 and Ref::Util::XS::is_plain_arrayref($args[0])
@args == 1
Ref::Util::XS::is_plain_arrayref($args[0])
Truth table100%3/3
A and B
A= @args == 1B= Ref::Util::XS::is_plain_arrayref($args[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 1977 | ▶ | my $binds = $state && $state->{Binds}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$state && $state->{'Binds'}
MC/DC50%1/2
$state && $state->{'Binds'}
$state
$state->{'Binds'}
Truth table66%2/3
A && B
A= $stateB= $state->{'Binds'}
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 1977 | ▶ | if ($binds && !$state->{InOrder}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$binds and not $state->{"InOrder"}
MC/DC100%2/2
$binds and not $state->{"InOrder"}
$binds
not $state->{"InOrder"}
Truth table100%3/3
A and not(B)
A= $bindsB= not $state->{"InOrder"}
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 134 | ▶ | _check_bound($self) unless @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 129 | ▶ | @args = _in_order($state, \@args) if @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 120 | $state->{AllBound} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 1963 | ▶ | return at_caller { $self->SUPER::execute(@args) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | # Execute the statement once for each row of values the fetch gives, as | ||||||||||||||||||||||||||||||||||||||||||
| 110 | # the DBI's execute_for_fetch does, and return what it returns. A | ||||||||||||||||||||||||||||||||||||||||||
| 111 | # statement whose placeholders are mapped takes each row as the values for | ||||||||||||||||||||||||||||||||||||||||||
| 112 | # its placeholders, in order: by number, or for names, as each first | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # appears; or, for named ones, as a hash by name. Each row's values go to | ||||||||||||||||||||||||||||||||||||||||||
| 114 | # the DBI by position, a value for each use, so a driver gets them as it | ||||||||||||||||||||||||||||||||||||||||||
| 115 | # would for "?" (roadmap 2026-0037). | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 40 | ▶ | sub execute_for_fetch ($self, $fetch, @status) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute_for_fetch: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | _binds($self) | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 40 | ▶ | or return at_caller { $self->SUPER::execute_for_fetch($fetch, @status) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 35 | my $state = $self->{private_ekorn}; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 35 | _no_lists_for_rows($state); | |||||||||||||||||||||||||||||||||||||||||
| 121 | 34 | my $keys = _row_keys($state); | |||||||||||||||||||||||||||||||||||||||||
| 122 | 78 | ▶ | my $in_order = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 78 | ▶ | my $row = $fetch->() or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 48 | $state->{AllBound} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 48 | return [_row_in_order($state, $keys, $row)]; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 34 | }; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 34 | local $state->{InOrder} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 34 | ▶ | return at_caller { $self->SUPER::execute_for_fetch($in_order, @status) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | # Execute the statement once for each row of values, as the DBI's | ||||||||||||||||||||||||||||||||||||||||||
| 133 | # execute_array does, and return what it returns: the rows come from the | ||||||||||||||||||||||||||||||||||||||||||
| 134 | # arrays given, a value for each placeholder in the order | ||||||||||||||||||||||||||||||||||||||||||
| 135 | # execute_for_fetch takes them, or from those bound with | ||||||||||||||||||||||||||||||||||||||||||
| 136 | # bind_param_array, or from ArrayTupleFetch. A statement whose | ||||||||||||||||||||||||||||||||||||||||||
| 137 | # placeholders are mapped is counted by its placeholders, not their uses, | ||||||||||||||||||||||||||||||||||||||||||
| 138 | # as the DBI's NUM_OF_PARAMS counts them (roadmap 2026-0037). The DBI's | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # own checks keep its messages, raised as it raises them. | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 43 | ▶ | sub execute_array ($self, $attrs, @arrays) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute_array: called CC=16 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | _binds($self) | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 43 | ▶ | or return at_caller { $self->SUPER::execute_array($attrs, @arrays) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 39 | my $state = $self->{private_ekorn}; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 39 | _no_lists_for_rows($state); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 38 | my $keys = _row_keys($state); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 38 | my $needed = @$keys; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 38 | ▶ | my $status = $attrs && $attrs->{ArrayTupleStatus}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$attrs && $attrs->{'ArrayTupleStatus'}
MC/DC100%2/2
$attrs && $attrs->{'ArrayTupleStatus'}
$attrs
$attrs->{'ArrayTupleStatus'}
Truth table100%3/3
A && B
A= $attrsB= $attrs->{'ArrayTupleStatus'}
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 38 | ▶ | return _dbi_error( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$status and not Ref::Util::XS::is_plain_arrayref($status)
MC/DC100%2/2
$status and not Ref::Util::XS::is_plain_arrayref($status)
$status
not Ref::Util::XS::is_plain_arrayref($status)
Truth table100%3/3
A and not(B)
A= $statusB= not Ref::Util::XS::is_plain_arrayref($status)
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | $self, | ||||||||||||||||||||||||||||||||||||||||||
| 150 | execute_array => 'ArrayTupleStatus attribute must be an arrayref', | ||||||||||||||||||||||||||||||||||||||||||
| 151 | ) if $status && !is_plain_arrayref($status); | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 37 | my $fetch; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 37 | ▶ | if (my $source = $attrs && $attrs->{ArrayTupleFetch}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$attrs && $attrs->{'ArrayTupleFetch'}
MC/DC100%2/2
$attrs && $attrs->{'ArrayTupleFetch'}
$attrs
$attrs->{'ArrayTupleFetch'}
Truth table100%3/3
A && B
A= $attrsB= $attrs->{'ArrayTupleFetch'}
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 7 | ▶ | return _dbi_error( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | $self, | ||||||||||||||||||||||||||||||||||||||||||
| 156 | execute_array => "Can't use both ArrayTupleFetch and explicit bind values", | ||||||||||||||||||||||||||||||||||||||||||
| 157 | ) if @arrays; | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 6 | ▶ | $fetch = _fetch_from($self, $source, $needed) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 30 | ▶ | if (@arrays) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 24 | ▶ | return _dbi_error( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | $self, | ||||||||||||||||||||||||||||||||||||||||||
| 165 | execute_array => @arrays . " bind values supplied but $needed expected", | ||||||||||||||||||||||||||||||||||||||||||
| 166 | ) unless @arrays == $needed; | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 22 | $state->{ParamArrays} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 22 | for my $i (keys @arrays) { | |||||||||||||||||||||||||||||||||||||||||
| 169 | 43 | ▶ | $self->bind_param_array($keys->[$i], $arrays[$i]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 27 | ▶ | my $given = $state->{ParamArrays} // {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$state->{"ParamArrays"} // {}
MC/DC100%1/1
$state->{"ParamArrays"} // {}
$state->{"ParamArrays"}
Truth table100%2/2
A
A= $state->{"ParamArrays"}
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 27 | my $count = keys %$given; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 27 | ▶ | return _dbi_error( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | $self, | ||||||||||||||||||||||||||||||||||||||||||
| 177 | execute_array => "$count bind values supplied but $needed expected", | ||||||||||||||||||||||||||||||||||||||||||
| 178 | ) unless $count == $needed; | ||||||||||||||||||||||||||||||||||||||||||
| 179 | my $rows | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 25 | = max(1, map { scalar @$_ } grep { is_plain_arrayref($_) } values %$given); | |||||||||||||||||||||||||||||||||||||||||
| 181 | 25 | my $row = 0; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 61 | ▶ | $fetch = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 61 | ▶ | return if $row >= $rows; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | my @values | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 36 | ▶ | = map { is_plain_arrayref($_) ? $_->[$row] : $_ } @$given{@$keys}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 36 | $row++; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 36 | return \@values; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 25 | }; | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 27 | ▶ | return $self->execute_for_fetch($fetch, $status ? $status : ()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | # Bind an array of values, one for each row execute_array executes, to a | ||||||||||||||||||||||||||||||||||||||||||
| 195 | # placeholder, as the DBI's bind_param_array does, and return what it | ||||||||||||||||||||||||||||||||||||||||||
| 196 | # returns. A statement whose placeholders are mapped takes the | ||||||||||||||||||||||||||||||||||||||||||
| 197 | # placeholder's number or name, with or without its sigil, where the | ||||||||||||||||||||||||||||||||||||||||||
| 198 | # DBI's takes only a number; attributes given are bound to every use of | ||||||||||||||||||||||||||||||||||||||||||
| 199 | # it, as bind_param binds them. Its arrays are kept with the statement's | ||||||||||||||||||||||||||||||||||||||||||
| 200 | # map, not in the DBI's ParamArrays, which only the driver's side of the | ||||||||||||||||||||||||||||||||||||||||||
| 201 | # handle can set (roadmap 2026-0037). | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 64 | ▶ | sub bind_param_array ($self, $param, $values, @attrs) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind_param_array: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | my $binds = _binds($self) | ||||||||||||||||||||||||||||||||||||||||||
| 204 | or return | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 64 | ▶ | at_caller { $self->SUPER::bind_param_array($param, $values, @attrs) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 56 | my $state = $self->{private_ekorn}; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 56 | _no_lists_for_rows($state); | |||||||||||||||||||||||||||||||||||||||||
| 208 | 55 | ▶ | return _dbi_error( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
Ref::Util::XS::is_ref($values) and not Ref::Util::XS::is_plain_arrayref($values)
MC/DC100%2/2
Ref::Util::XS::is_ref($values) and not Ref::Util::XS::is_plain_arrayref($values)
Ref::Util::XS::is_ref($values)
not Ref::Util::XS::is_plain_arrayref($values)
Truth table100%3/3
A and not(B)
A= Ref::Util::XS::is_ref($values)B= not Ref::Util::XS::is_plain_arrayref($values)
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | $self, bind_param_array => | ||||||||||||||||||||||||||||||||||||||||||
| 210 | "Value for parameter $param must be a scalar or an arrayref, not a " | ||||||||||||||||||||||||||||||||||||||||||
| 211 | . ref $values, | ||||||||||||||||||||||||||||||||||||||||||
| 212 | ) if is_ref($values) && !is_plain_arrayref($values); | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 53 | my $key = key_of($param); | |||||||||||||||||||||||||||||||||||||||||
| 214 | croakf 'Expected a placeholder of the statement (%s)', $param | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 53 | ▶ | unless $binds->{$key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 51 | $state->{ParamArrays}{$key} = $values; | |||||||||||||||||||||||||||||||||||||||||
| 217 | 51 | ▶ | return $self->bind_param($key, undef, @attrs) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@attrs and $attrs[0]
MC/DC100%2/2
@attrs and $attrs[0]
@attrs
$attrs[0]
Truth table100%3/3
A and B
A= @attrsB= $attrs[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | if @attrs && $attrs[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 50 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | # Return an iterator over the statement's results, executed with the bind | ||||||||||||||||||||||||||||||||||||||||||
| 223 | # values given, and run through the stages given after them; or, if the | ||||||||||||||||||||||||||||||||||||||||||
| 224 | # last stage is a sink, the sink's result. | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 424 | ▶ | sub iterate ($self, @args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 424 | return DBIx::Squirrel::Iterator->new($self, @args)->_or_sink; ## no critic (Subroutines::ProtectPrivateSubs) | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | # Return a result set over the statement's results: an iterator handing | ||||||||||||||||||||||||||||||||||||||||||
| 230 | # out rows as objects; or, if the last stage is a sink, the sink's result. | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 44 | ▶ | sub results ($self, @args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
results: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 44 | return DBIx::Squirrel::Results->new($self, @args)->_or_sink; ## no critic (Subroutines::ProtectPrivateSubs) | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | # Return the values given, or those in an array reference given alone, | ||||||||||||||||||||||||||||||||||||||||||
| 236 | # as unwrap_values does. Values not given in an array reference alone, | ||||||||||||||||||||||||||||||||||||||||||
| 237 | # as most aren't, are returned at once, without reading the driver's name | ||||||||||||||||||||||||||||||||||||||||||
| 238 | # through the handles' attributes. | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 220 | ▶ | sub _unwrap ($self, @args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unwrap: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | return @args | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 220 | ▶ | unless @args == 1 && is_plain_arrayref($args[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@args == 1 and Ref::Util::XS::is_plain_arrayref($args[0])
MC/DC100%2/2
@args == 1 and Ref::Util::XS::is_plain_arrayref($args[0])
@args == 1
Ref::Util::XS::is_plain_arrayref($args[0])
Truth table100%3/3
A and B
A= @args == 1B= Ref::Util::XS::is_plain_arrayref($args[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 30 | my $state = $self->{private_ekorn}; | |||||||||||||||||||||||||||||||||||||||||
| 243 | return unwrap_values( | ||||||||||||||||||||||||||||||||||||||||||
| 244 | $self->{Database}{Driver}{Name}, | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 19 | ▶ | sub { _values_taken($self) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 30 | ▶ | $state && $state->{Lists}, @args, | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$state && $state->{'Lists'}
MC/DC50%1/2
$state && $state->{'Lists'}
$state
$state->{'Lists'}
Truth table66%2/3
A && B
A= $stateB= $state->{'Lists'}
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | # Return how many values the statement takes in order: one for each | ||||||||||||||||||||||||||||||||||||||||||
| 251 | # placeholder the DBI sees, or each number, or none if they're named. | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 19 | ▶ | sub _values_taken ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_values_taken: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | my $binds = _binds($self) | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 19 | ▶ | or return $self->{NUM_OF_PARAMS}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 17 | return values_taken($binds); | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | # Return the statement's map of each placeholder's number or name to its | ||||||||||||||||||||||||||||||||||||||||||
| 259 | # positions, or nothing if the statement went to the DBI as written. | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 253 | ▶ | sub _binds ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_binds: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 253 | my $state = $self->{private_ekorn}; | |||||||||||||||||||||||||||||||||||||||||
| 262 | 253 | ▶ | return $state && $state->{Binds}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$state && $state->{'Binds'}
MC/DC50%1/2
$state && $state->{'Binds'}
$state
$state->{'Binds'}
Truth table66%2/3
A && B
A= $stateB= $state->{'Binds'}
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | # Croak unless a value has been bound to every use of each of the | ||||||||||||||||||||||||||||||||||||||||||
| 266 | # placeholders of a statement with numbered or named ones: given to | ||||||||||||||||||||||||||||||||||||||||||
| 267 | # execute or bind, which bind them all, or to bind_param. Unbound, the | ||||||||||||||||||||||||||||||||||||||||||
| 268 | # driver would read them as NULL, or fail. | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 50 | ▶ | sub _check_bound ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_bound: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 50 | my $state = $self->{private_ekorn}; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 50 | ▶ | return if $state->{AllBound}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 11 | my $binds = $state->{Binds}; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 11 | ▶ | my $bound = $state->{Bound} // {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$state->{"Bound"} // {}
MC/DC100%1/1
$state->{"Bound"} // {}
$state->{"Bound"}
Truth table100%2/2
A
A= $state->{"Bound"}
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | my @missing = sort grep { | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 11 | grep { !$bound->{$_} } | |||||||||||||||||||||||||||||||||||||||||
| 276 | 17 | @{ $binds->{$_} } | |||||||||||||||||||||||||||||||||||||||||
| 277 | } keys %$binds; | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 11 | ▶ | croakf 'Expected a value for each placeholder (none for %s)', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | join(', ', @missing) | ||||||||||||||||||||||||||||||||||||||||||
| 280 | if @missing; | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | # Return the values for a statement's placeholders, as values_for finds | ||||||||||||||||||||||||||||||||||||||||||
| 285 | # them, in the order of their positions, each as often as it's used, and | ||||||||||||||||||||||||||||||||||||||||||
| 286 | # each value in a list at a position of its own, given what the statement | ||||||||||||||||||||||||||||||||||||||||||
| 287 | # handle keeps about the statement. | ||||||||||||||||||||||||||||||||||||||||||
| 288 | # | ||||||||||||||||||||||||||||||||||||||||||
| 289 | # A statement without list placeholders keeps their order, so its values | ||||||||||||||||||||||||||||||||||||||||||
| 290 | # are put in it with a slice (roadmap 2026-0028). | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 110 | ▶ | sub _in_order ($state, $args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_in_order: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 110 | my $given = DBIx::Squirrel::Placeholders::_values_for($state->{Binds}, $args); ## no critic (Subroutines::ProtectPrivateSubs) | |||||||||||||||||||||||||||||||||||||||||
| 293 | 99 | ▶ | if (my $order = $state->{Order}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 77 | return @$given{@$order}; | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | # A list's values go to positions of their own, each pair a position | ||||||||||||||||||||||||||||||||||||||||||
| 297 | # and its value, put in order without a hash of them. | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 22 | my $placed = DBIx::Squirrel::Placeholders::_place_values($state, $given); ## no critic (Subroutines::ProtectPrivateSubs) | |||||||||||||||||||||||||||||||||||||||||
| 299 | 21 | my @in_order; | |||||||||||||||||||||||||||||||||||||||||
| 300 | 21 | ▶ | for (my $i = 0; $i < @$placed; $i += 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 39 | $in_order[$placed->[$i] - 1] = $placed->[$i + 1]; | |||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 21 | return @in_order; | |||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | # Return the numbers or names a row of values gives a statement values | ||||||||||||||||||||||||||||||||||||||||||
| 308 | # for, in the order it gives them: each number to the highest, as execute | ||||||||||||||||||||||||||||||||||||||||||
| 309 | # takes them, or the names in the order each first appears (roadmap | ||||||||||||||||||||||||||||||||||||||||||
| 310 | # 2026-0037, D1). A statement's handle keeps them. | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 72 | ▶ | sub _row_keys ($state) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_row_keys: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | return $state->{RowKeys} | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 72 | ▶ | if $state->{RowKeys}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 35 | my $binds = $state->{Binds}; | |||||||||||||||||||||||||||||||||||||||||
| 315 | return $state->{RowKeys} | ||||||||||||||||||||||||||||||||||||||||||
| 316 | = is_numbered($binds) | ||||||||||||||||||||||||||||||||||||||||||
| 317 | ? [1 .. values_taken($binds)] | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 35 | ▶ | : [sort { $binds->{$a}[0] <=> $binds->{$b}[0] } keys %$binds]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | # Return a row's values for a statement's placeholders in the order of | ||||||||||||||||||||||||||||||||||||||||||
| 323 | # their positions, a value for each use, as _in_order does, given what the | ||||||||||||||||||||||||||||||||||||||||||
| 324 | # statement handle keeps about it, the numbers or names its rows give | ||||||||||||||||||||||||||||||||||||||||||
| 325 | # values for, and the row: an array of values in that order, or, for a | ||||||||||||||||||||||||||||||||||||||||||
| 326 | # named statement, a hash of them by name. | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 48 | ▶ | sub _row_in_order ($state, $keys, $row) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_row_in_order: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 48 | ▶ | return _in_order($state, [$row]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | if is_plain_hashref($row); | ||||||||||||||||||||||||||||||||||||||||||
| 330 | return _in_order($state, $row) | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 42 | ▶ | if is_numbered($state->{Binds}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 26 | ▶ | croakf 'Expected %d bind values, not %d', scalar @$keys, scalar @$row | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | unless @$row == @$keys; | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 25 | my %values; | |||||||||||||||||||||||||||||||||||||||||
| 335 | 25 | @values{@$keys} = @$row; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 25 | return @values{@{ $state->{Order} }}; | |||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | # Return a fetch of rows, for execute_array, from what ArrayTupleFetch | ||||||||||||||||||||||||||||||||||||||||||
| 341 | # holds: a code reference, as it is, or an active statement handle, read | ||||||||||||||||||||||||||||||||||||||||||
| 342 | # a row at a time, with as many columns as the statement has | ||||||||||||||||||||||||||||||||||||||||||
| 343 | # placeholders. Otherwise, set the DBI's error, as it does, and return | ||||||||||||||||||||||||||||||||||||||||||
| 344 | # nothing. | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 6 | ▶ | sub _fetch_from ($self, $source, $needed) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fetch_from: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 6 | ▶ | return $source | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | if is_coderef($source); | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 5 | ▶ | return _dbi_error( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | $self, | ||||||||||||||||||||||||||||||||||||||||||
| 350 | execute_array => | ||||||||||||||||||||||||||||||||||||||||||
| 351 | "ArrayTupleFetch '$source' is not a code ref or statement handle", | ||||||||||||||||||||||||||||||||||||||||||
| 352 | ) unless $source isa 'DBI::st'; | ||||||||||||||||||||||||||||||||||||||||||
| 353 | return _dbi_error( | ||||||||||||||||||||||||||||||||||||||||||
| 354 | $self, | ||||||||||||||||||||||||||||||||||||||||||
| 355 | execute_array => | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 'ArrayTupleFetch sth is not Active, need to execute() it first', | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 3 | ▶ | ) unless $source->{Active}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 2 | my $fields = $source->{NUM_OF_FIELDS}; # an active statement has them | |||||||||||||||||||||||||||||||||||||||||
| 359 | 2 | ▶ | return _dbi_error( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | $self, | ||||||||||||||||||||||||||||||||||||||||||
| 361 | execute_array => | ||||||||||||||||||||||||||||||||||||||||||
| 362 | "$fields columns from ArrayTupleFetch sth but $needed expected", | ||||||||||||||||||||||||||||||||||||||||||
| 363 | ) if $fields != $needed; | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 1 | ▶ | return sub { $source->fetchrow_arrayref }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | # Croak if a statement has list placeholders: its handle is prepared for | ||||||||||||||||||||||||||||||||||||||||||
| 369 | # lists of the lengths it was given, so rows of values can't share it | ||||||||||||||||||||||||||||||||||||||||||
| 370 | # (roadmap 2026-0037, D4). | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 130 | ▶ | sub _no_lists_for_rows ($state) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_no_lists_for_rows: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 130 | my $lists = $state->{Lists}; | |||||||||||||||||||||||||||||||||||||||||
| 373 | 130 | ▶ | croakf 'Expected no list placeholder in a statement for rows of values (%s)', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | join ', ', sort values %$lists | ||||||||||||||||||||||||||||||||||||||||||
| 375 | if $lists; | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 127 | return; | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | # Set the DBI's error on a statement handle, with one of the DBI's own | ||||||||||||||||||||||||||||||||||||||||||
| 381 | # messages, as its execute_array and bind_param_array set them, so it's | ||||||||||||||||||||||||||||||||||||||||||
| 382 | # raised, printed or handled as the handle's attributes say, named for | ||||||||||||||||||||||||||||||||||||||||||
| 383 | # the method given, as the DBI names it; return what set_err returns. An | ||||||||||||||||||||||||||||||||||||||||||
| 384 | # error left from an earlier call is cleared first, as the DBI clears it | ||||||||||||||||||||||||||||||||||||||||||
| 385 | # at the start of each of its methods, or set_err would add to it. | ||||||||||||||||||||||||||||||||||||||||||
| 386 | 12 | ▶ | sub _dbi_error ($self, $method, $message) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbi_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 12 | $self->set_err(undef, undef); | |||||||||||||||||||||||||||||||||||||||||
| 388 | 12 | ▶ | return at_caller { $self->set_err($DBI::stderr, $message, undef, $method) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 29 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 392 | __END__ | ||||||||||||||||||||||||||||||||||||||||||