Iterator-DBI

 view release on metacpan or  search on metacpan

DBI.pm  view on Meta::CPAN

=for gpg
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

=head1 NAME

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

=head1 VERSION

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

=cut

use strict;
use warnings;
package Iterator::DBI;
our $VERSION = '0.02';

use base 'Exporter';
use vars qw/@EXPORT @EXPORT_OK %EXPORT_TAGS/;
@EXPORT  = qw(idb_rows);
@EXPORT_OK   = @EXPORT;

use Iterator;


# Function name: idb_rows
# Synopsis:      $iter = idb_rows ($dbh, $sql, @bind_vars);
# Description:   Iterates over a database query's results
# Created:       07/29/2005 by EJR
# Parameters:    $dbh - A DBI database handle
#                $sql - The query
#                @bind_vars - (optional) bind variables.
# Returns:       Row iterator (returns hash references)
# Exceptions:    Iterator::X::Parameter_Error
#                "idb_rows cannot prepare sql: <error string>"
#                "idb_rows cannot execute sql: <error string>"
#                "fetchrow_hashref: <error string>"
#                Iterator::X::Am_Now_Exhausted
sub idb_rows
{
    my ($dbh, $sql, @bind) = @_;
    my $sth;    # statement handle

    Iterator::X::Parameter_Error->throw
        ('idb_rows: $dbh parameter is not a database handle')
        unless UNIVERSAL::can($dbh, 'prepare');

    return Iterator->new (sub
    {
        # Prepare database statement, if not done alread
        unless ($sth)
        {
            $sth = $dbh->prepare($sql)
                or die "idb_rows cannot prepare sql: " . $dbh->errstr;

            unless ($sth->execute(@bind))
            {
                $sth->finish;
                undef $sth;     # allow garbage collection

DBI.pm  view on Meta::CPAN


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.

=item * Prepare error

String: "idb_rows cannot prepare sql: I<message>"

The DBI C<prepare> method returned an error.

=item * Execution error

String: "idb_rows cannot execute sql: I<message>"

The DBI C<execute> method returned an error.

=item * Fetch error

String: "idb_rows: fetch error: I<message>"

The DBI C<fetchrow_hashref> method returned an error.

=back

=head1 REQUIREMENTS

Requires the following additional modules:

L<Iterator>

L<DBI>

=head1 SEE ALSO

I<Higher Order Perl>, Mark Jason Dominus, Morgan Kauffman 2005.

L<http://perl.plover.com/hop/>

The L<Iterator> module.

The L<DBI> module.

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

=cut

=begin gpg

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)

iD8DBQFDC5R8Y96i4h5M0egRAtxIAJ9/FJ1TndC3JKlesiWUAred9JWW/wCcDVRA
dfUba0u3uWhaRP9zx3TaJEQ=
=jGbz
-----END PGP SIGNATURE-----

=end gpg



( run in 1.646 second using v1.01-cache-2.11-cpan-e1769b4cff6 )