On Tue, Sep 26, 2006 at 11:02:00AM -0700, Dean Arnold wrote:
> While testing my execute_array() implementation, I've added
> something that might be generally useful: a progress-report
> callback. I realize that ArrayTupleFetch might be adapted
> to provide the concept with a bit more coding in the app, but
> if all the app is doing is either dumping a file to the DBMS,
> or using a $sth to supply the data, it might be useful to have
> a "ArrayProgress" parameter that gets called occasionally.
> 
> My driver specific version is a stmt handle attribute that
> supplies an arrayref of [ $tupleincr, $callback ], where
> $tupleincr is the minimum number of tuples between invoking $callback,
> and $callback is just s CODE ref that gets called with the
> current number of tuples sent.
> 
> E.g.,
> 
> $sth->execute_array({
>       ArrayTupleStatus => [EMAIL PROTECTED],
>       ArrayTupleFetch => $sth,
>       ArrayProgress => [ 100, \&report_progress ]
> });
> 
> sub report_progress {
>       my $tuples = shift;
>       print "\r Sent $tuples...";
> }
> 
> Would this be a useful addition to the API, or just more code clutter ?

Umm. Doesn't really seem worth it when it's easy to do via
ArrayTupleFetch. Something like:

  $sth->execute_array({
        ArrayTupleStatus => [EMAIL PROTECTED],
        ArrayTupleFetch => sub {
            report_progress($fetch_count) if ++$fetch_count % 100 == 0;
            return $sth->fetchrow_arrayref;
        },
  });

(If you pass ArrayTupleFetch as an sth then execute_array just turns it
into a closure anyway, so there's no extra cost there.)

Tim.

Reply via email to