Iterator::DBI - An iterator for returning DBI query results.



NAME

Iterator::DBI - An iterator for returning DBI query results.


VERSION

This documentation describes version 0.02 of Iterator::DBI, August 23, 2005.


SYNOPSIS

 use Iterator::DBI;
 # Iterate over a database SELECT query.
 # (returns one hash reference per row).
 $iter = idb_rows ($dbh, $sql);
 $iter = idb_rows ($dbh, $sql, @bind);


DESCRIPTION

This module contains a function to return an iterator (see the the Iterator manpage module) that returns the rows of a database query, one at a time.

This is marginally more useful than simply calling prepare and execute, and then repeatedly calling fetchrow_hashref; since this one function bundles up the calls to all three of those DBI methods.

But the real usefulness of this interface is that it can be chained together with other Iterator functions. The idb_rows iterator has the same interface as any other interface, making it interchangeable with iterators of any other source (for example, files), and usable with the iterator manipulation functions in the the Iterator::Util manpage module.


FUNCTIONS

idb_rows
 $it = idb_rows ($dbh, $sql);
 $it = idb_rows ($dbh, $sql, @bind);

Returns an iterator to return rows from a database query. Each row is returned as a hashref, as from fetchrow_hashref|DBI/fetchrow_hashref from the DBI module.

If the query requires bind variables, they may be passed in @bind.

Example:

 $dbh = DBI->connect (...);
 $iter = idb_rows ($dbh, 'select foo, bar from quux');
 $row_ref = $iter->value;


EXPORTS

The following symbol is exported to the caller's namespace:

 idb_rows


DIAGNOSTICS

Iterator::DBI uses the Exception::Class manpage objects for throwing exceptions. If you're not familiar with Exception::Class, don't worry; these exception objects work just like $@ does with die and croak, but they are easier to work with if you are trapping errors.

You can learn more about Iterator exceptions in the Iterator module documentation.


REQUIREMENTS

Requires the following additional modules:

the Iterator manpage

the DBI manpage


SEE ALSO

Higher Order Perl, Mark Jason Dominus, Morgan Kauffman 2005.

http://perl.plover.com/hop/

The the Iterator manpage module.

The the DBI manpage module.


AUTHOR / COPYRIGHT

Eric J. Roode, roode@cpan.org

Copyright (c) 2005 by Eric J. Roode. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

To avoid my spam filter, please include "Perl", "module", or this module's name in the message's subject line, and/or GPG-sign your message.