in reply to Re: Hash-clobbering in DBD's fetchrow_hashref
in thread Hash-clobbering in DBD's fetchrow_hashref
Now, what is the value of $hash{id}? It is baz, because that was the last key/val pair in the list. You know that hashes behave this way, why should DBI do something different?my %hash = ( id => 'foo', id => 'bar', id => 'baz', );
Here is a little test you might be interested in:
Even when you are dealing with just SQL, this is expected behavior. It is not at all uncommon to use column aliases, and if you really did "distinguish ... the fields in order to get the select to work" then you "shouldn't have to do it twice to get the hashref to work". Remember, just qualifying the column by appending the table name to it DOES NOT change the column name:my $sth = $dbh->prepare('select 1,1,1'); $sth->execute; print Dumper $sth->fetchrow_hashref; $sth->execute; print Dumper $sth->fetchrow_arrayref; $sth = $dbh->prepare('select 1 as a,1 as b,1 as c'); $sth->execute; print Dumper $sth->fetchrow_hashref;
mysql> select baz.foo, baz.bar from baz; +---------------+------+ | foo | bar | +---------------+------+ | <tag> & stuff | 0 | | one | 1 | | two | 2 | | three | 3 | | zero | 0 | | null | NULL | +---------------+------+ 6 rows in set (0.00 sec)
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Hash-clobbering in DBD's fetchrow_hashref
by Cody Pendant (Prior) on Aug 27, 2003 at 22:12 UTC | |
by jeffa (Bishop) on Aug 28, 2003 at 01:04 UTC |