Currently, a result set has to be completely materialized
on the client before it can be fetched via DBD::Sponge:

    my $cursor = ...
    my $rows = [];
    while ( !$cursor->eof ) {
      my $row = [ map { $cursor->fields->...
      $cursor->next;
      push @$rows, $row;
    }
    $cursor->close;
    $sponge->prepare('', { rows => $rows, NUM_OF_FIELDS => ... } );
  }

Large result sets may exhaust available memory. We could
reduce memory usage at the cost of CPU time:

    my $cursor = ...
    my $rows = sub {
      $cursor->close, return if $cursor->eof;
      my $row = [ map { $cursor->fields->...
      $cursor->next;
      return $row;
    };
    $sponge->prepare('', { rows => $rows, NUM_OF_FIELDS => ... } );

I'm aware that the call to close() isn't guaranteed, but I assume
the $cursor is closed when DESTROYed.

In DBD::Sponge, the fetch method needs to deal with the
code reference:

  sub fetch {
    ...
    my $rows = $sth->{rows};
    my $row = ref $rows eq 'CODE' ? $rows->() : shift @$rows;

Of course, DBD::Sponge is no longer absorptive.
Any opinions?


Steffen

Reply via email to