Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #2 from chiselwright/master

execute_array()
  • Loading branch information...
commit efc9492c447361e71c245db41508861b02b8fcb2 2 parents 4d057df + 8729225
@ginesr ginesr authored
View
1  .gitignore
@@ -0,0 +1 @@
+*\.sw?
View
6 Build.PL
@@ -20,6 +20,12 @@ my $build = Module::Build->new(
create_makefile_pl => 'traditional',
recursive_test_files => 1,
add_to_cleanup => [ '*.bak', ],
+
+ meta_merge => {
+ resources => {
+ repository => 'https://github.com/bluescreen10/dbd-mock',
+ },
+ },
);
$build->create_build_script;
View
3  Changes
@@ -1,5 +1,8 @@
Revision history for Perl extension DBD::Mock.
+{{NEXT}}
+ - Add git-repo url to meta-data
+
1.43
- Segregated into different packages
- Removed code coverage from POD
View
36 lib/DBD/Mock/st.pm
@@ -20,6 +20,10 @@ sub bind_param {
return 1;
}
+sub bind_param_array {
+ bind_param(@_);
+}
+
sub bind_param_inout {
my ( $sth, $param_num, $val, $max_len ) = @_;
@@ -37,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};
View
34 t/030_st_execute_array.t
@@ -0,0 +1,34 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+# test style cribbed from t/013_st_execute_bound_params.t
+
+BEGIN {
+ use_ok('DBD::Mock');
+ use_ok('DBI');
+}
+
+my $sql = 'INSERT INTO staff (first_name, last_name, dept) VALUES(?, ?, ?)';
+
+{
+ my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
+ my $sth = eval { $dbh->prepare( $sql ) };
+
+ # taken from: https://metacpan.org/module/DBI#Statement-Handle-Methods
+ $dbh->{RaiseError} = 1; # save having to check each method call
+ $sth = $dbh->prepare($sql);
+
+ $sth->bind_param_array(1, [ 'John', 'Mary', 'Tim' ]);
+ $sth->bind_param_array(2, [ 'Booth', 'Todd', 'Robinson' ]);
+ # TODO: $sth->bind_param_array(3, "SALES"); # scalar will be reused for each row
+
+ eval {
+ $sth->execute_array( { ArrayTupleStatus => \my @tuple_status } );
+ };
+ ok( ! $@, 'Called execute_array() ok' )
+ or diag $@;
+}
+
+done_testing;

0 comments on commit efc9492

Please sign in to comment.
Something went wrong with that request. Please try again.