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

First, the fetchall_* methods fetch all of the rows, so you usually don't see fetchall in the conditional of while loops. Second, $_ isn't set anywhere in your code, so I don't know why you're testing it (the while() does not set it).

Replies are listed 'Best First'.
Re^3: DBI and fetchall_arrayref
by mje (Curate) on Feb 20, 2009 at 13:21 UTC
    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)||[]}) ) ) { ... }
      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!