Plain text
| Download
- package DBIx::FetchAll;
-
- =head1 NAME
-
- DBIx::FetchAll - provides sugar for DBI $sth
-
- =cut
-
- use warnings;
- use strict;
-
- =head1 METHODS
-
- =head2 fetchall_hash
-
- %table = $sth->fetchall_hash;
- $table_ref = $sth->fetchall_hash;
-
- C<%table> looks like this:
-
- (
- colA => [ $row1_colA, $row2_colA, ... ],
- colB => [ $row1_colB, $row2_colB, ... ],
- colC => [ $row1_colC, $row2_colC, ... ],
- ...
- )
-
- =cut
-
- sub DBI::st::fetchall_hash {
- my $sth = shift;
- my @cols = @{$sth->{'NAME'}};
- my %table = map { $_ => [] } @cols;
-
- while(my @row = $sth->fetchrow_array) {
- push @{$table{$_}}, shift @row for(@cols);
- }
-
- wantarray ? %table : \%table;
- }
-
- =head1 AUTHOR
-
- Jan Henning Thorsen
-
- =cut
-
- 1;