| 1 | package DBIx::Librarian::Statement::SelectMany; | ||
| 2 | |||
| 3 | require 5.005; | ||
| 4 | use strict; | ||
| 5 | use base qw(DBIx::Librarian::Statement); | ||
| 6 | use vars qw($VERSION); | ||
| 7 | $VERSION = '0.4'; | ||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | DBIx::Librarian::Statement::SelectMany - multi-row SELECT statement | ||
| 12 | |||
| 13 | =head1 DESCRIPTION | ||
| 14 | |||
| 15 | SELECT statement that expects to retrieve multiple (zero or more) | ||
| 16 | rows from the database. | ||
| 17 | |||
| 18 | All values fetched will be stored in arrays in the data hash, either as | ||
| 19 | |||
| 20 | $data->{node}[0]->{column} | ||
| 21 | $data->{node}[1]->{column} | ||
| 22 | |||
| 23 | or as | ||
| 24 | |||
| 25 | $data->{column}[0] | ||
| 26 | $data->{column}[1] | ||
| 27 | |||
| 28 | depending on how the output column names are specified in the SQL. | ||
| 29 | |||
| 30 | =cut | ||
| 31 | |||
| 32 | sub fetch { | ||
| 33 | my ($self, $data) = @_; | ||
| 34 | |||
| 35 | my $i = 0; | ||
| 36 | while (my $hash_ref = $self->{STH}->fetchrow_hashref) { | ||
| 37 | while (my ($key, $val) = each %$hash_ref) { | ||
| 38 | if ($key =~ /\./) { | ||
| 39 | my ($obj, $subkey) = split /\./, $key; | ||
| 40 | $data->{$obj}[$i]->{$subkey} = $val; | ||
| 41 | } else { | ||
| 42 | $data->{$key}[$i] = $val; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | $i++; | ||
| 46 | last if $i >= $self->{MAXSELECTROWS}; | ||
| 47 | } | ||
| 48 | |||
| 49 | return $i; | ||
| 50 | } | ||
| 51 | |||
| 52 | |||
| 53 | 1; | ||
| 54 | |||
| 55 | =head1 AUTHOR | ||
| 56 | |||
| 57 | Jason W. May <jmay@pobox.com> | ||
| 58 | |||
| 59 | =head1 COPYRIGHT | ||
| 60 | |||
| 61 | Copyright (C) 2001 Jason W. May. All rights reserved. | ||
| 62 | This module is free software; you can redistribute it and/or | ||
| 63 | modify it under the same terms as Perl itself. |