On Sun, 08 Dec 2002 15:00:55 -0500, Randall Perry <[EMAIL PROTECTED]> spoke gently:
> Asked this question last summer and didn't get an answer, so I stuck with
> DBI 1.19 which uses the old behavior of selectall_hashref, returning an
> array of hashes.
>
> I'm going to be upgrading DBI and would appreciate it if someone could give
> me a code snippet showing how to use selectall_arrayref to get the old
> behavior of selectall_hashref. The text below, from the change log, says to
> use selectall_arrayref to return an array of hashes.
>
> Whereas selectall_hashref used to do this with just a $statement argument,
> I'm guessing selectall_arrayref requires another argument, which I haven't
> been able to figure out how to use from the docs.
> Changed selectall_hashref to return a hash ref (from fetchall_hashref)
> and not an array of hashes as it has since DBI 1.15 (end March 2001).
> WARNING: THIS CHANGE WILL BREAK ANY CODE USING selectall_hashref()!
> Sorry, but I think this is an important regularization of the API.
> To get previous selectall_hashref() behaviour (an array of hash refs)
> change $ary_ref = $dbh->selectall_hashref( $statement, undef, @bind);
> to $ary_ref = $dbh->selectall_arrayref($statement, { Columns=>{} },
> @bind);
The key is the { Columns=>{} } in the paragraph you quoted. A typical
snippet from my code:
my $sth = $dbh->prepare('SELECT....blahblah...');
my $data = $dbh->selectall_arrayref($sth, {Columns=>{}});
print ref $data->[0]; # Prints 'HASH'
HTH
-Sebastian
Us nature mystics got to stick together. -Ed Abbey