There is working patch for this bug.
With this changes are all my DB unittest working.
diff -urNp DBD-Mock-1.43/lib/DBD/Mock/db.pm DBD-Mock-1.43-patched/lib/DBD/Mock/db.pm
--- DBD-Mock-1.43/lib/DBD/Mock/db.pm 2011-08-29 03:12:03.000000000 +0000
+++ DBD-Mock-1.43-patched/lib/DBD/Mock/db.pm 2012-08-09 12:40:37.000000000 +0000
@@ -54,6 +54,21 @@ sub prepare {
return;
}
+ if (my $session = $dbh->FETCH('mock_session')) {
+ eval {
+ $session->verify_statement($dbh, $statement);
+ # copy the result sets so that
+ # we can re-use the session
+ $dbh->STORE( 'mock_add_resultset' => [ @{ $session->current_state->{results} } ] );
+ };
+ if ($@) {
+ my $session_error = $@;
+ chomp $session_error;
+ $dbh->DBI::set_err(1, "Session Error: ${session_error}. Statement: ${statement}");
+ return;
+ }
+ }
+
my $sth = DBI::_new_sth( $dbh, { Statement => $statement } );
$sth->trace_msg( "Preparing statement '${statement}'\n", 1 );
diff -urNp DBD-Mock-1.43/lib/DBD/Mock/Session.pm DBD-Mock-1.43-patched/lib/DBD/Mock/Session.pm
--- DBD-Mock-1.43/lib/DBD/Mock/Session.pm 2011-08-29 03:12:03.000000000 +0000
+++ DBD-Mock-1.43-patched/lib/DBD/Mock/Session.pm 2012-08-09 12:38:42.000000000 +0000
@@ -91,10 +91,6 @@ sub verify_statement {
"Bad 'statement' value '$SQL' in current state in DBD::Mock::Session ("
. $self->{name} . ")";
}
-
- # copy the result sets so that
- # we can re-use the session
- $dbh->STORE( 'mock_add_resultset' => [ @{ $current_state->{results} } ] );
}
sub verify_bound_params {
diff -urNp DBD-Mock-1.43/t/bug_71438_fetchrow_hashref.t DBD-Mock-1.43-patched/t/bug_71438_fetchrow_hashref.t
--- DBD-Mock-1.43/t/bug_71438_fetchrow_hashref.t 1970-01-01 00:00:00.000000000 +0000
+++ DBD-Mock-1.43-patched/t/bug_71438_fetchrow_hashref.t 2012-08-09 12:23:12.000000000 +0000
@@ -0,0 +1,70 @@
+#!/usr/bin/perl
+use Test::More tests => 6;
+use strict;
+use warnings;
+use Test::Exception;
+use DBI;
+use DBD::Mock;
+
+my $dbh = DBI->connect('dbi:Mock:', '', '', { PrintError => 0, RaiseError => 1});
+
+my $query = 'SELECT foo, bar FROM baz WHERE id=?';
+my @session = (
+ {
+ statement => $query,
+ results => [
+ ['foo', 'bar'],
+ [1, 'test1'],
+ [2, 'test2']
+ ],
+ bound_params => [ 1 ],
+ },
+ {
+ statement => $query,
+ results => [
+ ['abc', 'xyz'],
+ [7, 'test7'],
+ [8, 'test8']
+ ],
+ bound_params => [ 2 ],
+ },
+);
+$dbh->{mock_session} = DBD::Mock::Session->new(@session);
+
+# First query
+my $sth = $dbh->prepare($query);
+$sth->execute(1);
+
+is_deeply(
+ $sth->fetchrow_hashref(),
+ {foo => 1, bar => 'test1'}
+);
+
+is_deeply(
+ $sth->fetchrow_hashref(),
+ {foo => 2, bar => 'test2'}
+);
+
+is_deeply(
+ $sth->fetchrow_hashref(),
+ undef
+);
+
+# Second query
+$sth = $dbh->prepare($query);
+$sth->execute(2);
+
+is_deeply(
+ $sth->fetchrow_hashref(),
+ {abc => 7, xyz => 'test7'}
+);
+
+is_deeply(
+ $sth->fetchrow_hashref(),
+ {abc => 8, xyz => 'test8'}
+);
+
+is_deeply(
+ $sth->fetchrow_hashref(),
+ undef
+);