in reply to Re^2: DBI and fetchall_arrayref
in thread DBI and fetchall_arrayref

First, the fetchall_* methods fetch all of the rows

Not always true. The fetchall_arrayref takes a $max_rows optional argument which limits the number of rows fetched in one go to $max_rows. The example shown was in fact using $max_rows. e.g., from the DBI docs:

If $max_rows is defined and greater than or equal to zero then it is used to limit the number of rows fetched before returning. fetchall_arrayref() can then be called again to fetch more rows. This is especially useful when you need the better performance of fetchall_arrayref() but don't have enough memory to fetch and return all the rows in one go.

Here's an example (assumes RaiseError is enabled):

my $rows = []; # cache for batches of rows while( my $row = ( shift(@$rows) || # get row from cache, or reload ca +che: shift(@{$rows=$sth->fetchall_arrayref(unde +f,10_000)||[]}) ) ) { ... }

Replies are listed 'Best First'.
Re^4: DBI and fetchall_arrayref
by hbm (Hermit) on Feb 20, 2009 at 13:37 UTC
    The example shown was in fact using $max_rows

    In fairness, I added $max_rows as an update, after runrig replied.

    mje, are you familiar with the error I mentioned? Thanks!