Iterator::DBI - An iterator for returning DBI query results.
This documentation describes version 0.02 of Iterator::DBI, August 23, 2005.
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);
This module contains a function to return an iterator (see the Iterator 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 Iterator::Util module.
$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.
fetchrow_hashref|DBI/fetchrow_hashref
If the query requires bind variables, they may be passed in @bind.
@bind
Example:
$dbh = DBI->connect (...); $iter = idb_rows ($dbh, 'select foo, bar from quux'); $row_ref = $iter->value;
The following symbol is exported to the caller's namespace:
idb_rows
Iterator::DBI uses Exception::Class 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.
$@
die
croak
You can learn more about Iterator exceptions in the Iterator module documentation.
Parameter Errors
Class: Iterator::X::Parameter_Error
Iterator::X::Parameter_Error
You called idb_rows with one or more bad parameters. Since this is almost certainly a coding error, there is probably not much use in handling this sort of exception.
As a string, this exception provides a human-readable message about what the problem was.
Prepare error
String: "idb_rows cannot prepare sql: message"
The DBI prepare method returned an error.
prepare
Execution error
String: "idb_rows cannot execute sql: message"
The DBI execute method returned an error.
execute
Fetch error
String: "idb_rows: fetch error: message"
The DBI fetchrow_hashref method returned an error.
fetchrow_hashref
Requires the following additional modules:
Iterator
DBI
Higher Order Perl, Mark Jason Dominus, Morgan Kauffman 2005.
http://perl.plover.com/hop/
The Iterator module.
The DBI module.
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.
To install Iterator::DBI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Iterator::DBI
CPAN shell
perl -MCPAN -e shell install Iterator::DBI
For more information on module installation, please visit the detailed CPAN module installation guide.