Is selectrow_array really supposed to return an "empty list"
am 06.12.2005 12:41:18 von Martin.Evans
The documentation for selecrow_array in DBI 1.49 says:
"If any method fails, and "RaiseError" is not set, selectrow_array will return
an empty list."
use DBI;
use strict;
use Data::Dumper;
my $dbh = DBI->connect('dbi:mysql:xxx','yyy','zzz');
$dbh->{RaiseError} = 0;
$dbh->{PrintError} = 0;
my @r = $dbh->selectrow_array('select xxx from yyy');
print "rows = ", $#r, "\n";
print "err = ", $dbh->err, "\n";
print "errstr = ", $dbh->errstr, "\n";
print Dumper(@r);
and column xxx and table yyy does not exist I get:
rows = 0
err = 1146
errstr = Table 'yyy' doesn't exist
$VAR1 = undef;
when I expected -1 for rows - as in:
perl -e 'my @a=(); print $#a;' outputs -1 for an empty list, not 0 for a list
containing an undef.
It does not seem to matter what the driver is - I tried dbi::ODBC too.
Martin
--
Martin J. Evans
Easysoft Ltd, UK
Development
Re: Is selectrow_array really supposed to return an "empty list"
am 06.12.2005 16:32:11 von Tim.Bunce
Looks like a bug. The C version of selectrow_array is using
XSRETURN_UNDEF which will return an undef not an empty list.
Patch to follow, hopefully today.
Thanks!
Tim.
On Tue, Dec 06, 2005 at 11:41:18AM -0000, Martin J. Evans wrote:
> The documentation for selecrow_array in DBI 1.49 says:
>
> "If any method fails, and "RaiseError" is not set, selectrow_array will return
> an empty list."
>
> use DBI;
> use strict;
> use Data::Dumper;
> my $dbh = DBI->connect('dbi:mysql:xxx','yyy','zzz');
> $dbh->{RaiseError} = 0;
> $dbh->{PrintError} = 0;
> my @r = $dbh->selectrow_array('select xxx from yyy');
> print "rows = ", $#r, "\n";
> print "err = ", $dbh->err, "\n";
> print "errstr = ", $dbh->errstr, "\n";
> print Dumper(@r);
>
> and column xxx and table yyy does not exist I get:
>
> rows = 0
> err = 1146
> errstr = Table 'yyy' doesn't exist
> $VAR1 = undef;
>
> when I expected -1 for rows - as in:
>
> perl -e 'my @a=(); print $#a;' outputs -1 for an empty list, not 0 for a list
> containing an undef.
>
> It does not seem to matter what the driver is - I tried dbi::ODBC too.
>
> Martin
> --
> Martin J. Evans
> Easysoft Ltd, UK
> Development
>