On 3/24/07, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
> >>>>> "rose" == rose  <[EMAIL PROTECTED]> writes:
> rose> I'm using Rose with a fairly large MySQL database and using an
> rose> iterator like
>
> rose>     my $itr = Bar->get_bars_iterator();
> rose>     while($itr->next()) {
>
> rose> won't work because by default, an iterator will read in all records from
> rose> the DB, which won't fit into memory.
>
> Looking at the code, it appears to call $sth->fetch on every call to ->next.

Exactly.  RDBO::Manager's iterators do not fetch everything up front.
They calls $sth->fetch on each iteration.  What the DBD::* DBI driver
does behind the scenes is another matter, however.  What database are
you using?  If you're using MySQL, you might want to try setting
mysql_use_result on your Rose::DB data source:

http://search.cpan.org/dist/Rose-DB/lib/Rose/DB/MySQL.pm#mysql_use_result

More info here:

http://search.cpan.org/dist/DBD-mysql/lib/DBD/mysql.pm#mysql_use_result

On 3/23/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> So I thought: Couldn't Rose have 'pager' objects acting like iterators,
> but fetching all available data in configurable chunks?
>
> The attached patch allows to say
>
>     my $pager = Bar->get_bars_pager( per_page => 20 );
>     while($pager->next()) {
>
> and the pager will act like an iterator, but instead of running
> out after one page, it will create a new iterator under the hood
> and continue until there's no more records to be fetched.

The problem with that approach is that it can give inconsistent
results if the contents of database change between the creation of
each of the "single page" iterators.  If that doesn't bother you, then
by all means keep using the code you've created.  But I'm hesitant to
put such a thing in the core distribution (and then pepper the docs
with warnings that most people won't read).

-John

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to