Skip Menu |

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

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

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

Bug Information
Severity: Normal
Broken in: 1.37
Fixed in: 1.39



Subject: [PATCH] Small fetch() fix
Hello, I think I just found a small bug in DBD::Mock::st::fetch(). I was trying to test a code similar to this one: my $sth = $dbh->prepare("SELECT user, host, password FROM user"); $sth->execute; my ($user, $host, $password); $sth->bind_columns(\$user, \$host, \$password); while ($sth->fetch) { ... } and found that $sth->fetch() always returns true, even when there is no more values. A more complete example is attached. I think the problem simply is that the arrayref is autovivified by the for() loop. The attached patch fixes the bug. Regards -- Close the world, txEn eht nepO.
Subject: dbd-mock.pl
#!perl -T use strict; use DBI; # configure the mocked MySQL connection my $dbh = DBI->connect("dbi:Mock:", "", ""); # prepare the mocked data $dbh->{mock_add_resultset} = { sql => "SELECT user, host, password FROM user", results => [ [ "user", "host", "password" ], [ "plonk", "localhost", "urkkk" ], ], }; my $sth = $dbh->prepare("SELECT user, host, password FROM user"); $sth->execute; my ($user, $host, $password); $sth->bind_columns(\$user, \$host, \$password); while ($sth->fetch) { # if the next line is commented, the while() loops endlessly #last unless defined $user; print " * user=$user, host=$host, password=$password\n"; }
Subject: DBD-Mock-1.37-st-fetch.diff
diff -ru DBD-Mock-1.37-orig/lib/DBD/Mock.pm DBD-Mock-1.37-new/lib/DBD/Mock.pm --- DBD-Mock-1.37-orig/lib/DBD/Mock.pm 2008-06-12 20:05:26.000000000 +0200 +++ DBD-Mock-1.37-new/lib/DBD/Mock.pm 2008-06-24 14:36:41.030633092 +0200 @@ -683,6 +683,7 @@ my $tracker = $sth->FETCH( 'mock_my_history' ); my $record = $tracker->next_record; + return unless defined $record; if ( my @cols = $tracker->bind_cols() ) { for my $i ( grep { ref $cols[$_] } 0..$#cols ) { Seulement dans DBD-Mock-1.37-new/lib/DBD: .Mock.pm.swp