Hi,
When using DBI in a mixed Oracle and MySQL environment, the form
$sth->fetchrow_hashref('NAME_lc');
is very useful when one wants to get rid of Oracle's obsession with
capital COLUMN-NAMES. However, the
$sth->fetchall_arrayref( {} );
is a bit problematic, because there is no way to control how
fetchrow_hashref is called inside DBI.pm (at least no way I know of).
Attached is a patch attempting to correct this by providing the
following way of calling fetchall_arrayref:
$sth->fetchall_arrayref( {}, 'NAME_lc' );
As I am not a regular DBI developer, I would be happy if someone
would comment on the patch.
- peter
--
Peter Andreasen <[EMAIL PROTECTED]> | http://pandr.dk | ln -s /dev/random ~/.plan
------ Fingerprint: 4311 664F 8034 EB15 C75B 30F0 9729 BCD9 0E11 4DA4 -------
--- DBI.pm-old Mon Jun 4 21:01:39 2001
+++ DBI.pm Mon Jun 18 10:57:18 2001
@@ -308,7 +308,7 @@
fetchrow_array => undef,
fetchrow => undef, # old alias for fetchrow_array
- fetchall_arrayref => { U =>[1,2] },
+ fetchall_arrayref => { U =>[1,3] },
blob_read => { U =>[4,5,'$field, $offset, $len [, \\$buf [, $bufoffset]]']
},
blob_copy_to_file => { U =>[3,3,'$field, $filename_or_handleref'] },
@@ -1116,6 +1116,7 @@
sub fetchall_arrayref {
my $sth = shift;
my $slice= shift || [];
+ my $name = shift;
my $mode = ref $slice;
my @rows;
my $row;
@@ -1142,7 +1143,12 @@
}
else {
# XXX assumes new ref each fetchhash
- push @rows, $row while ($row = $sth->fetchrow_hashref);
+ if ($name) {
+ push @rows, $row while ($row = $sth->fetchrow_hashref($name));
+ }
+ else {
+ push @rows, $row while ($row = $sth->fetchrow_hashref);
+ }
}
}
else { Carp::croak("fetchall_arrayref($mode) invalid") }
@@ -3267,6 +3273,7 @@
$tbl_ary_ref = $sth->fetchall_arrayref;
$tbl_ary_ref = $sth->fetchall_arrayref( $slice_array_ref );
$tbl_ary_ref = $sth->fetchall_arrayref( $slice_hash_ref );
+ $tbl_ary_ref = $sth->fetchall_arrayref( {}, $name );
The C<fetchall_arrayref> method can be used to fetch all the data to be
returned from a prepared and executed statement handle. It returns a
@@ -3287,7 +3294,8 @@
When passed a hash reference, C<fetchall_arrayref> uses L</fetchrow_hashref>
to fetch each row as a hash reference. If the parameter hash is empty then
fetchrow_hashref is simply called in a tight loop and the keys in the hashes
-have whatever name lettercase is returned by default from fetchrow_hashref.
+have the name lettercase specified by C<$name> or, if C<$name> was not
+given, whatever is returned by default from fetchrow_hashref.
If the parameter hash is not empty, then it is used as a slice to
select individual columns by name. The names should be lower case