DBI Developers,
> Speak before you patch
I would like to extend DBI's fetchall_hashref and selectall_hashref
methods to handle multiple keys. Being new to DBI, I miss Michael Peppler's
Sybperl::Simple's useful HashOfHashOfHash method. The following are
my proposed new syntaxes:
$sth->fetchall_hashref(@key_field);
$dbh->selectall_hashref($statement, [EMAIL PROTECTED] [, \%attr[, @bind_values]]);
For example, let FOO and BAR form a composite key. Then:
$sth = $dbh->prepare("SELECT FOO, BAR, NAME, BAZ FROM TABLE");
$sth->execute;
$hash_ref = $sth->fetchall_hashref(qw(FOO BAR));
print "NAME for FOO=4 and BAR=2 is $hash_ref->{4}{2}{NAME}\n";
or
$sql = "SELECT FOO, BAR, NAME, BAZ FROM TABLE";
$hash_ref = $sth->selectall_hashref($sql, [qw(FOO BAR)]);
print "BAZ for FOO=4 and BAR=2 is $hash_ref->{4}{2}{BAZ}\n";
My current patch can handle @key_field of 1 .. 4 elements.
I would appreciate any comments.
Cheers,
Daniel Lewart
[EMAIL PROTECTED]