Skip Menu |

This queue is for tickets about the DBI CPAN distribution.

Report information
The Basics
Id: 68126
Status: resolved
Priority: 0/
Queue: DBI

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

Bug Information
Severity: Normal
Broken in: 1.616
Fixed in: 1.601



Subject: fetchall_arrayref([], $n) return is undefined
In DBI-1.616, fetchall_arrayref() works, but fetchall_arrayref([], $n) does not. The latter form returns an undefined value, even when there are valid rows. Both forms work in DBI-1.601. The environment where I saw the problem is: Linux x64 (Arch Linux, kernel ver 2.6.38.5) perl 5.12.3 Informix 11.50FC8 DBD-Informix 2008.0513 DBI-1.616
Subject: bug_fetchrow_arrayref.pl
#!/usr/bin/perl -w # # DBD::Informix Example - fetchall_arrayref # # @(#)$Id: x03fetchrow_arrayref.pl,v 100.1 2002/02/08 22:50:08 jleffler Exp $ # # Copyright 1998 Jonathan Leffler # Copyright 2000 Informix Software Inc # Copyright 2002 IBM use DBI; my $DATABASE="optifacts"; my $TABLE="blocks"; printf("DEMO1 Sample DBD::Informix Program running.\n"); printf("Variant: using fetchall_arrayref()\n"); my($dbh) = DBI->connect("DBI:Informix:$DATABASE") or die; my($sth) = $dbh->prepare("SELECT * FROM $TABLE") or die; $sth->execute() or die; my($row_ref); $row_ref = $sth->fetchall_arrayref([], 1000); # this fails. row_ref is undefined. #$row_ref = $sth->fetchall_arrayref(); # this works. my (@rows) = @{$row_ref}; printf("%d rows fetched\n",scalar(@rows)); for ($i = 0; $i <= $#rows; $i++) { my (@row) = @{$rows[$i]}; for ($j = 0; $j <= $#row; $j++) { printf("%8s ", $row[$j]); } printf("\n"); } undef $sth; $dbh->disconnect(); printf("\nDEMO1 Sample Program over.\n\n");
Show quoted text
> Will you please fix this regression that happened somewhere around version 1.603?
Over three years ago. Show quoted text
> One way to fix it is remove line 2007 from DBI.pm version 1.616. This is the line in question: > return undef if $max_rows and not $sth->FETCH('Active'); > An initial, non-active fetch _can_ specify a maximum number of rows to fetch, > and I use this capability through DBD-Informix.
I'm not sure what you mean by "initial, non-active fetch". After $sth->execute() on a select statement $sth->FETCH('Active') should be true. If it's not then that's a bug in the driver. See the tests around line 250 of t/10examp.t I've added a few more in the current trunk https://svn.perl.org/modules/dbi/trunk/t/10examp.t
I've encountered this as well with SQLite in some odd cases. At the very least, the return value should not be undef, as the documentation says: "If there are no rows to return, fetchall_arrayref returns a reference to an empty array."
On Mon Sep 19 21:30:53 2011, DAGOLDEN wrote: Show quoted text
> I've encountered this as well with SQLite in some odd cases. > > At the very least, the return value should not be undef, as the > documentation says: "If there are no rows to return, fetchall_arrayref > returns a reference to an empty array."
Would this help: -If there are no rows to return, C<fetchall_arrayref> returns a reference +If called on an I<inactive> statement handle, C<fetchall_arrayref> returns undef. + +If there are no rows left to return from an I<active> statement handle, C<fetchall_arrayref> returns a reference to an empty array. If an error occurs, C<fetchall_arrayref> returns the Show quoted text
> I've encountered this as well with SQLite in some odd cases.
I'd like to see a test case.
I've patched the docs as described. Thanks.