DBIx::Librarian::Statement::SelectMany - multi-row SELECT statement


DBIx-Librarian documentation Contained in the DBIx-Librarian distribution.

Index


Code Index:

NAME

Top

DBIx::Librarian::Statement::SelectMany - multi-row SELECT statement

DESCRIPTION

Top

SELECT statement that expects to retrieve multiple (zero or more) rows from the database.

All values fetched will be stored in arrays in the data hash, either as

    $data->{node}[0]->{column}
    $data->{node}[1]->{column}

or as

    $data->{column}[0]
    $data->{column}[1]

depending on how the output column names are specified in the SQL.

AUTHOR

Top

Jason W. May <jmay@pobox.com>

COPYRIGHT

Top


DBIx-Librarian documentation Contained in the DBIx-Librarian distribution.

package DBIx::Librarian::Statement::SelectMany;

require 5.005;
use strict;
use base qw(DBIx::Librarian::Statement);
use vars qw($VERSION);
$VERSION = '0.4';

sub fetch {
    my ($self, $data) = @_;

    my $i = 0;
    while (my $hash_ref = $self->{STH}->fetchrow_hashref) {
	while (my ($key, $val) = each %$hash_ref) {
	    if ($key =~ /\./) {
		my ($obj, $subkey) = split /\./, $key;
		$data->{$obj}[$i]->{$subkey} = $val;
	    } else {
		$data->{$key}[$i] = $val;
	    }
	}
	$i++;
	last if $i >= $self->{MAXSELECTROWS};
    }

    return $i;
}


1;