| 1 | package DBD::Mock::st; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 40 | our $imp_data_size = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | sub bind_col { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 13 | ▶ | my ( $sth, $param_num, $ref, $attr ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind_col: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 13 | my $tracker = $sth->FETCH('mock_my_history'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 13 | $tracker->bind_col( $param_num, $ref ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 13 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | sub bind_param { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 14 | ▶ | my ( $sth, $param_num, $val, $attr ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind_param: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 14 | my $tracker = $sth->FETCH('mock_my_history'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 14 | $tracker->bound_param( $param_num, $val, $attr ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 14 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | sub bind_param_array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | bind_param(@_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind_param_array: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | sub bind_param_inout { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | my ( $sth, $param_num, $val, $max_len ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind_param_inout: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # check that $val is a scalar ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | ( UNIVERSAL::isa( $val, 'SCALAR' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | || $sth->{Database} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | ▶ | ->set_err( 1, "need a scalar ref to bind_param_inout, not $val" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # check for positive $max_len | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ( $max_len > 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | || $sth->{Database} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | ->set_err( 1, "need to specify a maximum length to bind_param_inout" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | my $tracker = $sth->FETCH('mock_my_history'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | $tracker->bound_param( $param_num, $val ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | sub execute_array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | my ( $sth, $attr, @bind_values ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute_array: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # no bind values means we're relying on prior calls to bind_param_array() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # for our data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | my $tracker = $sth->FETCH('mock_my_history'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # don't use a reference; there's some magic attached to it somewhere | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # so make it a lovely, simple array as soon as possible | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | my @bound = @{ $tracker->bound_params() }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | foreach my $p (@bound) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | my $result = $sth->execute( @$p ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # store the result from execute() if ArrayTupleStatus attribute is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # passed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | push @{ $attr->{ArrayTupleStatus} }, $result | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | ▶ | if (exists $attr->{ArrayTupleStatus}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # TODO: the docs say: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # When called in scalar context the execute_array() method returns the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # number of tuples executed, or undef if an error occurred. Like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # execute(), a successful execute_array() always returns true regardless | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # of the number of tuples executed, even if it's zero. If there were any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # errors the ArrayTupleStatus array can be used to discover which tuples | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # failed and with what errors. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # When called in list context the execute_array() method returns two | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # scalars; $tuples is the same as calling execute_array() in scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # context and $rows is the number of rows affected for each tuple, if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # available or -1 if the driver cannot determine this. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # We have glossed over this... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | return scalar @bound; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | sub execute { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 148 | ▶ | my ( $sth, @params ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: called CC=15 SCAR=27.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 148 | my $dbh = $sth->{Database}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 148 | ▶ | unless ( $dbh->{mock_can_connect} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | $dbh->set_err( 1, "No connection present" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 147 | ▶ | unless ( $dbh->{mock_can_execute} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | $dbh->set_err( 1, "Cannot execute" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 145 | ▶ | $dbh->{mock_can_execute}++ if $dbh->{mock_can_execute} < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 145 | my $tracker = $sth->FETCH('mock_my_history'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 145 | ▶ | if ( $tracker->has_failure() ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 3 | $dbh->set_err( $tracker->get_failure() ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 142 | ▶ | if (@params) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 46 | $tracker->bind_params(@params); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 142 | ▶ | if ( my $session = $dbh->{mock_session} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 49 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 49 | my $state = $session->current_state; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 49 | $session->verify_statement( $sth->{Statement}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 43 | $session->verify_bound_params( $tracker->bound_params() ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # Load a copy of the results to return (minus the field | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # names) into the tracker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 40 | my @results = @{ $state->{results} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 40 | shift @results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 40 | $tracker->{return_data} = \@results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 49 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 9 | my $session_error = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 9 | chomp $session_error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 9 | $sth->set_err( 1, "Session Error: ${session_error}" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 9 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 133 | $tracker->mark_executed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 133 | my $fields = $tracker->fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 133 | ▶ | $sth->STORE( NUM_OF_FIELDS => scalar @{ $fields ? $fields : [] } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 133 | $sth->STORE( NAME => $fields ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 133 | $sth->STORE( NUM_OF_PARAMS => $tracker->num_params ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # handle INSERT statements and the mock_last_insert_ids | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # We should only increment these things after the last successful INSERT. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # -RobK, 2007-10-12 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | #use Data::Dumper;warn Dumper $dbh->{mock_last_insert_ids}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 133 | ▶ | if ( $dbh->{Statement} =~ /^\s*?insert(?:\s+ignore)?\s+into\s+(\S+)/i ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 23 | ▶ | if ( $tracker->{last_insert_id} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | $dbh->{mock_last_insert_id} = $tracker->{last_insert_id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | ▶ | } elsif ( $dbh->{mock_last_insert_ids} | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$dbh->{"mock_last_insert_ids"} and exists $dbh->{"mock_last_insert_ids"}{$1}
MC/DC50%1/2
$dbh->{"mock_last_insert_ids"} and exists $dbh->{"mock_last_insert_ids"}{$1}
$dbh->{"mock_last_insert_ids"}
exists $dbh->{"mock_last_insert_ids"}{$1}
Truth table66%2/3
A and B
A= $dbh->{"mock_last_insert_ids"}B= exists $dbh->{"mock_last_insert_ids"}{$1}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | && exists $dbh->{mock_last_insert_ids}{$1} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 7 | $dbh->{mock_last_insert_id} = $dbh->{mock_last_insert_ids}{$1}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 15 | $dbh->{mock_last_insert_id}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | #warn "$dbh->{mock_last_insert_id}\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # always return 0E0 for Selects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 133 | ▶ | if ( $dbh->{Statement} =~ /^\s*?select/i ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 97 | return '0E0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 36 | ▶ | return ( $sth->rows() || '0E0' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$sth->rows || '0E0'
MC/DC100%1/1
$sth->rows || '0E0'
$sth->rows
Truth table100%2/2
A
A= $sth->rows
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | sub fetch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 146 | ▶ | my ($sth) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 146 | my $dbh = $sth->{Database}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 146 | ▶ | unless ( $dbh->{mock_can_connect} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | $dbh->set_err( 1, "No connection present" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 145 | ▶ | unless ( $dbh->{mock_can_fetch} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 3 | $dbh->set_err( 1, "Cannot fetch" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 142 | ▶ | $dbh->{mock_can_fetch}++ if $dbh->{mock_can_fetch} < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 142 | my $tracker = $sth->FETCH('mock_my_history'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 142 | ▶ | my $record = $tracker->next_record | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 123 | ▶ | if ( my @cols = $tracker->bind_cols() ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 6 | for my $i ( grep { ref $cols[$_] } 0 .. $#cols ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 14 | ${ $cols[$i] } = $record->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 123 | return $record; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | sub fetchrow_array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 33 | ▶ | my ($sth) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetchrow_array: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 33 | my $row = $sth->DBD::Mock::st::fetch(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 32 | ▶ | return unless ref($row) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 30 | return @{$row}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | sub fetchrow_arrayref { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 87 | ▶ | my ($sth) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetchrow_arrayref: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 87 | return $sth->DBD::Mock::st::fetch(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | sub fetchrow_hashref { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 10 | ▶ | my ( $sth, $name ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetchrow_hashref: called CC=6 SCAR=18.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 10 | my $dbh = $sth->{Database}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # handle any errors since we are grabbing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # from the tracker directly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 10 | ▶ | unless ( $dbh->{mock_can_connect} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | $dbh->set_err( 1, "No connection present" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 10 | ▶ | unless ( $dbh->{mock_can_fetch} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | $dbh->set_err( 1, "Cannot fetch" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 9 | ▶ | $dbh->{mock_can_fetch}++ if $dbh->{mock_can_fetch} < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # first handle the $name, it will default to NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 9 | ▶ | $name ||= 'NAME'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$name ||= "NAME"
MC/DC0%0/1
$name ||= "NAME"
$name
Truth table50%1/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # then fetch the names from the $sth (per DBI spec) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 9 | my $fields = $sth->FETCH($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # now check the tracker ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 9 | my $tracker = $sth->FETCH('mock_my_history'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # and collect the results | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 9 | ▶ | if ( my $record = $tracker->next_record() ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 6 | my @values = @{$record}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 6 | return { map { $_ => shift(@values) } @{$fields} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 3 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | #XXX Isn't this supposed to return an array of hashrefs? -RobK, 2007-10-15 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | sub fetchall_hashref { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 5 | ▶ | my ( $sth, $keyfield ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetchall_hashref: called CC=15 SCAR=30.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 5 | my $dbh = $sth->{Database}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # handle any errors since we are grabbing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # from the tracker directly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 5 | ▶ | unless ( $dbh->{mock_can_connect} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $dbh->set_err( 1, "No connection present" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 5 | ▶ | unless ( $dbh->{mock_can_fetch} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | $dbh->set_err( 1, "Cannot fetch" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 5 | ▶ | $dbh->{mock_can_fetch}++ if $dbh->{mock_can_fetch} < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # get the case conversion to use for hash key names (NAME/NAME_lc/NAME_uc) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 5 | ▶ | my $hash_key_name = $sth->{Database}->FETCH('FetchHashKeyName') || 'NAME'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$sth->{'Database'}->FETCH('FetchHashKeyName') || 'NAME'
MC/DC0%0/1
$sth->{'Database'}->FETCH('FetchHashKeyName') || 'NAME'
$sth->{'Database'}->FETCH('FetchHashKeyName')
Truth table50%1/2
A
A= $sth->{'Database'}->FETCH('FetchHashKeyName')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # get a hashref mapping field names to their corresponding indexes. indexes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # start at zero | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 5 | my $names_hash = $sth->FETCH("${hash_key_name}_hash"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # as of DBI v1.48, the $keyfield argument can be either an arrayref of field | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # names/indexes or a single field name/index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 5 | ▶ | my @key_fields = ref $keyfield ? @{$keyfield} : $keyfield; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 5 | my $num_fields = $sth->FETCH('NUM_OF_FIELDS'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # get the index(es) of the given key field(s). a key field can be specified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # as either the name of a field or an integer column number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 5 | my @key_indexes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 5 | foreach my $field (@key_fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 6 | ▶ | if (defined $names_hash->{$field}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 3 | push @key_indexes, $names_hash->{$field}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | ▶ | elsif (DBI::looks_like_number($field) && $field >= 1 && $field <= $num_fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
DBI::looks_like_number($field) and $field >= 1 and $field <= $num_fields
DBI::looks_like_number($field) and $field >= 1
MC/DC0%0/3
DBI::looks_like_number($field) and $field >= 1 and $field <= $num_fields
DBI::looks_like_number($field)
$field >= 1
$field <= $num_fields
Truth table25%1/4
A and B and C
A= DBI::looks_like_number($field)B= $field >= 1C= $field <= $num_fields
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # convert from column number to array index. column numbers start at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # one, while indexes start at zero | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 3 | push @key_indexes, $field - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | my $err = "Could not find key field '$field' (not one of " . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | join(' ', keys %{$names_hash}) . ')'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $dbh->set_err( 1, $err ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 5 | my $tracker = $sth->FETCH('mock_my_history'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 5 | my $rethash = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # now loop through all the records ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 5 | ▶ | while ( my $record = $tracker->next_record() ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # populate the hash, adding a layer of nesting for each key field | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # specified by the user | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 10 | my $ref = $rethash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 10 | foreach my $index (@key_indexes) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 12 | my $value = $record->[$index]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 12 | ▶ | $ref->{$value} = {} if ! defined $ref->{$value}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 12 | $ref = $ref->{$value}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # copy all of the returned data into the most-nested level of the hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 10 | foreach my $field (keys %{$names_hash}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 30 | my $index = $names_hash->{$field}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 30 | $ref->{$field} = $record->[$index]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 5 | return $rethash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | sub last_insert_id { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 6 | ▶ | my ( $sth, @params ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last_insert_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 6 | return $sth->{Database}->last_insert_id( @params ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | sub finish { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 38 | ▶ | my ($sth) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finish: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 38 | $sth->FETCH('mock_my_history')->is_finished('yes'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | sub rows { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 43 | ▶ | my ($sth) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rows: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 43 | $sth->FETCH('mock_num_rows'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | sub FETCH { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 121 | ▶ | my ( $sth, $attrib ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FETCH: called CC=28 SCAR=34.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 121 | $sth->trace_msg("Fetching ST attribute '$attrib'\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 121 | my $tracker = $sth->{mock_my_history}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 121 | $sth->trace_msg( "Retrieved tracker: " . ref($tracker) . "\n" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # NAME attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 121 | ▶ | if ( $attrib eq 'NAME' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 11 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 12 | return [ @{ $tracker->fields } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | elsif ( $attrib eq 'NAME_lc' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 2 | return [ map { lc($_) } @{ $tracker->fields } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | elsif ( $attrib eq 'NAME_uc' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 1 | return [ map { uc($_) } @{ $tracker->fields } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # NAME_hash attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | elsif ( $attrib eq 'NAME_hash' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 6 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 6 | return { map { $_ => $i++ } @{ $tracker->fields } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | elsif ( $attrib eq 'NAME_hash_lc' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 1 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 1 | return { map { lc($_) => $i++ } @{ $tracker->fields } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | elsif ( $attrib eq 'NAME_hash_uc' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 1 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 1 | return { map { uc($_) => $i++ } @{ $tracker->fields } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # others | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | elsif ( $attrib eq 'NUM_OF_FIELDS' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 2 | return $tracker->num_fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | elsif ( $attrib eq 'NUM_OF_PARAMS' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | return $tracker->num_params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | elsif ( $attrib eq 'TYPE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my $num_fields = $tracker->num_fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | return [ map { $DBI::SQL_VARCHAR } ( 0 .. $num_fields ) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | elsif ( $attrib eq 'Active' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 5 | return $tracker->is_active; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | elsif ( $attrib !~ /^mock/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 2 | ▶ | if ( $sth->{Database}->{mock_attribute_aliases} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | exists ${ $sth->{Database}->{mock_attribute_aliases}->{st} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | {$attrib} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | my $mock_attrib = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $sth->{Database}->{mock_attribute_aliases}->{st}->{$attrib}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | if ( ref($mock_attrib) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | return $mock_attrib->($sth); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | return $sth->FETCH($mock_attrib); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 2 | return $sth->SUPER::FETCH($attrib); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | # now do our stuff... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 88 | ▶ | if ( $attrib eq 'mock_my_history' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 12 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | return $tracker; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | elsif ( $attrib eq 'mock_execution_history' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | return $tracker->execution_history(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | elsif ( $attrib eq 'mock_statement' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 2 | return $tracker->statement; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | elsif ( $attrib eq 'mock_params' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 5 | return $tracker->bound_params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | elsif ( $attrib eq 'mock_param_attrs' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 3 | return $tracker->bound_param_attrs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | elsif ( $attrib eq 'mock_records' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 1 | return $tracker->return_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | ▶ | elsif ( $attrib eq 'mock_num_records' || $attrib eq 'mock_num_rows' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$attrib eq "mock_num_records" or $attrib eq "mock_num_rows"
MC/DC100%2/2
$attrib eq "mock_num_records" or $attrib eq "mock_num_rows"
$attrib eq "mock_num_records"
$attrib eq "mock_num_rows"
Truth table100%3/3
A or B
A= $attrib eq "mock_num_records"B= $attrib eq "mock_num_rows"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 48 | return $tracker->num_rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | elsif ( $attrib eq 'mock_current_record_num' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 11 | return $tracker->current_record_num; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | elsif ( $attrib eq 'mock_fields' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 1 | return $tracker->fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | elsif ( $attrib eq 'mock_is_executed' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 4 | return $tracker->is_executed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | elsif ( $attrib eq 'mock_is_finished' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 5 | return $tracker->is_finished; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | elsif ( $attrib eq 'mock_is_depleted' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 7 | return $tracker->is_depleted; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | die "I don't know how to retrieve statement attribute '$attrib'\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | sub STORE { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 693 | ▶ | my ( $sth, $attrib, $value ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORE: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 693 | $sth->trace_msg("Storing ST attribute '$attrib'\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 693 | ▶ | if ( $attrib =~ /^mock/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 140 | return $sth->{$attrib} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | elsif ( $attrib =~ /^NAME/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # no-op... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 210 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 343 | ▶ | $value ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$value ||= 0
MC/DC100%1/1
$value ||= 0
$value
Truth table100%2/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 343 | return $sth->SUPER::STORE( $attrib, $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 140 | ▶ | sub DESTROY { undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 40 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||