Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add execute_array() method to DBD::Mock::st

This is an early prototype that no longer dies when we call execute_array() on
a mocked $dbh - but the testing doesn't yet have very high coverage to prove
that it behaves as expected.
  • Loading branch information...
commit 87292259f380cc5046e01a06b37777dd0c777c75 1 parent 09e5fb9
@chiselwright authored
Showing with 32 additions and 0 deletions.
  1. +32 −0 lib/DBD/Mock/st.pm
View
32 lib/DBD/Mock/st.pm
@@ -41,6 +41,38 @@ sub bind_param_inout {
return 1;
}
+sub execute_array {
+ my ( $sth, $attr, @bind_values ) = @_;
+
+ # no bind values means we're relying on prior calls to bind_param_array()
+ # for our data
+ my $tracker = $sth->FETCH('mock_my_history');
+ # don't use a reference; there's some magic attached to it somewhere
+ # so make it a lovely, simple array as soon as possible
+ my @bound = @{ $tracker->bound_params() };
+ foreach my $p (@bound) {
+ my $result = $sth->execute( @$p );
+ # store the result from execute() if ArrayTupleStatus attribute is
+ # passed
+ push @{ $attr->{ArrayTupleStatus} }, $result
+ if (exists $attr->{ArrayTupleStatus});
+ }
+
+ # TODO: the docs say:
+ # When called in scalar context the execute_array() method returns the
+ # number of tuples executed, or undef if an error occurred. Like
+ # execute(), a successful execute_array() always returns true regardless
+ # of the number of tuples executed, even if it's zero. If there were any
+ # errors the ArrayTupleStatus array can be used to discover which tuples
+ # failed and with what errors.
+ # When called in list context the execute_array() method returns two
+ # scalars; $tuples is the same as calling execute_array() in scalar
+ # context and $rows is the number of rows affected for each tuple, if
+ # available or -1 if the driver cannot determine this.
+ # We have glossed over this...
+ return scalar @bound;
+}
+
sub execute {
my ( $sth, @params ) = @_;
my $dbh = $sth->{Database};
Please sign in to comment.
Something went wrong with that request. Please try again.