Skip Menu |

This queue is for tickets about the DBD-Mock CPAN distribution.

Report information
The Basics
Id: 66815
Status: resolved
Priority: 0/
Queue: DBD-Mock

People
Owner: Nobody in particular
Requestors: NPW [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 1.39
Fixed in: (no value)



Subject: DBD::Mock::Session error clobbered by subsequent method call on undef variable
Hi, I've noticed that when using a DBD::Mock::Session, if you exhaust the states defined whilst using the mock database handle, you get an error (as expected), but in certain cases at least, the real error is shadowed by a subsequent error caused by DBD::Mock attempting to use an undef statement handle variable. This results in a misleading error message in the test results. I attach a test case, and a patch for the specific case I came across which makes the test pass. I've checked this against v1.39. However, it looks like the same mistake also occurs elsewhere in DBD/Mock.pm - the return value of a ->prepare call is used without checking it is valid first. I'd attempt to fix them all but I'm pushed for time, so for now I'm just demonstrating the problem. I would hope the others are as simply fixed. Thanks for writing/maintaining DBD::Mock Nick
Subject: Mock.pm.diff
--- Mock.faulty.pm 2011-03-23 14:46:48.625442907 +0000 +++ Mock.fixed.pm 2011-03-23 14:45:02.520440818 +0000 @@ -322,7 +322,8 @@ if ($dbh->FETCH('AutoCommit')) { $dbh->STORE('AutoCommit', 0); $begin_work_commit = 1; - my $sth = $dbh->prepare( 'BEGIN WORK' ); + return + unless my $sth = $dbh->prepare( 'BEGIN WORK' ); my $rc = $sth->execute(); $sth->finish(); return $rc;
Subject: bug_0002.t
#!/usr/bin/perl use Test::More tests => 7; use strict; use warnings; use Test::Exception; use DBI; use DBD::Mock; my @session = ( { statement => 'BEGIN WORK', results => [], }, { statement => 'SELECT count(*) as cnt FROM some_table', results => [ ['cnt'], [1], ], }, { statement => 'COMMIT', results => [], }, ); my $dbh = DBI->connect('dbi:Mock:', '', '', { PrintError => 0, RaiseError => 1 }); # Add just part of the expected session, such that the next step would be a 'BEGIN WORK' $dbh->{mock_session} = DBD::Mock::Session->new(@session); # Now try and do the steps in @session, wrapping each in a transaction my $ix = 1; foreach my $step (@session) { my $sth = $dbh->prepare($step->{statement}); ok $sth, "step $ix, prepared statement"; ok $sth->execute($step->{bound_params}), "step $ix, executed statement"; my $results = $sth->fetchall_arrayref; ++$ix; } # This should fail with a useful message, but the original message gets clobbered by # "Can't call method "execute" on an undefined value£ throws_ok { $dbh->begin_work; } qr/\QSession states exhausted, only '3' in DBD::Mock::Session\E/;
Since I discover there is a new maintainer, I should mention that I have some fixes to this and some other small issues on github, if they're still useful: https://github.com/wu-lee/dbd-mock I was trying to get these integrated to Autarch's repo, communicating directly on github. Out of curiosity, what is the canonical repository now? N
Subject: Re: [rt.cpan.org #66815] DBD::Mock::Session error clobbered by subsequent method call on undef variable
Date: Wed, 22 Jun 2011 11:00:38 -0300
To: bug-DBD-Mock [...] rt.cpan.org
From: Mariano Wahlmann <Mariano.Wahlmann [...] gmail.com>
Yes.. I'm going to be taking care of it. Could you explain the nature of your fixes, I don't mind including them in the next revision. The repo I'm using for such releases is: https://github.com/bluescreen10/DBD-Mock On Tue, Jun 21, 2011 at 12:21 PM, Nick Woolley via RT < bug-DBD-Mock@rt.cpan.org> wrote: Show quoted text
> Queue: DBD-Mock > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=66815 > > > Since I discover there is a new maintainer, I should mention that I have > some fixes to this and some other small issues on github, if they're > still useful: > > https://github.com/wu-lee/dbd-mock > > I was trying to get these integrated to Autarch's repo, communicating > directly on github. Out of curiosity, what is the canonical repository > now? > > N >
On Wed Jun 22 10:00:55 2011, Mariano.Wahlmann@gmail.com wrote: Show quoted text
> Yes.. I'm going to be taking care of it.
Excellent, kudos for taking this on. Show quoted text
> Could you explain the nature of your fixes, I don't mind including them in > the next revision.
I've tried to explain what I've done in the commit log messages: https://github.com/wu-lee/dbd-mock/commits/master Let me know if that isn't clear, in the context of each diff, and I can be more specific. Show quoted text
> The repo I'm using for such releases is: > https://github.com/bluescreen10/DBD-Mock
You appear to have started this repository from scratch, and all the development history is therefore absent. Why not fork from Autarch's repository and declare the fork the master copy? That way the history of the project is kept and can be used to mine for clues (this is a very valuable source if information in my experience): https://github.com/autarch/dbd-mock It also means you ought to be able to get my changes more easily, since I also forked from that repository. Cheers, N
Fixed in 1.42