On Tue, Jan 10, 2006 at 12:47:54PM +0100, Peter J. Holzer wrote:
> or selectall_arrayhashref? 
> 
> Anyway, I rather frequently find that the "most natural" way to
> represent a query result is an array of hashes: Each row is hashref, but
> the the rows are in an array(ref) so that the order is preserved, and
> the columns can be accessed by name.
> 
> Proposed use:
> 
> my $emp = $dbh->selectall_hasharrayref("select * from emp order by ename");
> 
> for (@$emp) {
>     print "$_->{ename} ($_->{empno}): $_->{job}\n";
> }
> 
> or
> 
> for ($first .. $last) {
>     print $emp->[$_]{ename}, "\n";
> }
> 
> or something like that.
> 
> What do you think?

Anything wrong with the existing

    my $emp = $dbh->selectall_arrayref("...", { Slice => {} });

?

Note that selectall_*arrayref* defines the outermost data that the
method returns. What's inside that is controlled by attributes.

For example, want an array or arrays where the inner arrays contain
only the 2nd and 3rd fields? Easy:

    my $emp = $dbh->selectall_arrayref("...", { Slice => [2,3] });

Please spread the word. Way too many people seem to not know about this!

Tim.

Reply via email to