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 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.

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 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.

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

  • Parameter Errors

    Class: 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.

  • Execution error

    String: "idb_rows cannot execute sql: message"

    The DBI execute method returned an error.

  • Fetch error

    String: "idb_rows: fetch error: message"

    The DBI fetchrow_hashref method returned an error.

REQUIREMENTS

Requires the following additional modules:

Iterator

DBI

SEE ALSO

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

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

The Iterator module.

The DBI 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.