in reply to DBI::fetchall_arrayref() error

After some inspection, here's the deal:
fetchall_arrayref always returns an arrayref, which is always a true value. The underlying cursor is finished when the referenced array is empty OR HAS LESS ELEMENTS THAN REQUESTED. Thus, the revised idiom:
while (my $rows = $sth->fetchall_arrayref( [@slice], $maxrows)) { last unless @$rows; # do stuff last if @$rows < $maxrows; } die $sth->errstr if $sth->errstr;
which doesn't look that great, with the two lasts and the always-true while $ref (unless some DBD decides to return undef on failure)... can anyone clean it up?

Replies are listed 'Best First'.
Re: Re: DBI::fetchall_arrayref() error
by Anonymous Monk on Jan 12, 2004 at 18:01 UTC
    It seems the XS version returns undef after all data is returned:
    /* to simplify application logic we return undef without an error * +/ /* if we've fetched all the rows and called with a batch_row_count +*/ return &sv_undef;
    ...but the code does not handle slices, and bounces it back to the perl sub.