On Fri, May 03, 2002 at 10:24:07AM +0100, Simon Oliver wrote:
> Tim Bunce wrote:
> > 
> > 4/ Add the ability to fetch a subset of rows in a single call.
> > I'm thinking in terms of adding a parameter to fetchall_arrayref
> > to request that only N rows be fetched.
>
> I use a GetRows function for this purpose - it's basically a copy of the
> selectall_arrayref/fetchall_arrayref code, with added $top parameter -
> syntax is:
> 
> $ary_ref = GetRows($dbh, $stmt, $top, \%attr, @bind)
> 
> $dbh        a database handle
> $stmt       a prepared statement handle or SQL statement
> $top        a possitive integer to limit the number of rows returned
> \%attr      a hash reference to pass driver specific hints
> @bind       a list of bind parameters
> 
> If $top <1 it returns all rows
> 
> If $top > 0, $sth->finish is called before the function returns.  
> 
> Recently I have considered changing the spec so that $sth->finish is not
> called automatically in order to facilitate retrieving more $top rows from
> $sth later.  However, this leads to a problem whereby, if $stmt is a SQL
> statment (requiring the funtion to create a temporary statement handle),
> if $sth->finish is not called before returning from the function but there
> are rows left in the query an error will occur as the function returns and
> the statement handle is detroyed.  This can be solved by only calling
> $sth->finish if $top > 1 and !ref($stmt), but this would nead to be
> clearly documented.  (Did that make any sense?)

Yeap, that's the plan.

> > I'm also thinking of adding
> > a parameter to pass in a reference to any array onto which you'd
> > like the new rows pushed.
> That would also be useful.
> 
> But how would you implement these changes without compromising backward
> compatibility?

Firstly I doubt that many (or even any) drivers have implemented their
own fetchall_arrayref method. Most (all) would simply use the DBI's one.

Secondly the attribute to specify the max rows can be specified as
being a hint that some old drivers might ignore. Same goes for
passing in the array ref to push rows onto.

Tim.

Reply via email to