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