DBI doc curiosity

DBI doc curiosity

am 20.08.2007 08:21:47 von ron

Hi Tim

Under the write-up for fetchall_hashref is some sample code:
$dbh->{FetchHashKeyName} = 'NAME_lc';
$sth = $dbh->prepare("SELECT FOO, BAR, ID, NAME, BAZ FROM TABLE");
$sth->execute;
$hash_ref = $sth->fetchall_hashref('id');
print "Name for id 42 is $hash_ref->{42}->{name}\n";

However, after a call to $dbh -> primary_key_info(...), it seems the only
acceptable values for the parameter in the call to fetchall_hashref() are
TABLE_CAT, TABLE_SCHEM, TABLE_NAME, and KEY_SEQ. Is that right?
--
Ron Savage
ron@savage.net.au
http://savage.net.au/

Re: DBI doc curiosity

am 20.08.2007 09:07:23 von hjp

--LQksG6bCIzRHxTLp
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 2007-08-20 16:21:47 +1000, Ron Savage wrote:
> Under the write-up for fetchall_hashref is some sample code:
> $dbh->{FetchHashKeyName} =3D 'NAME_lc';
> $sth =3D $dbh->prepare("SELECT FOO, BAR, ID, NAME, BAZ FROM TABLE");
> $sth->execute;
> $hash_ref =3D $sth->fetchall_hashref('id');
> print "Name for id 42 is $hash_ref->{42}->{name}\n";
>=20
> However, after a call to $dbh -> primary_key_info(...), it seems the only
> acceptable values for the parameter in the call to fetchall_hashref() are
> TABLE_CAT, TABLE_SCHEM, TABLE_NAME, and KEY_SEQ. Is that right?

The example assumes that there is a table called "TABLE" with at least
the fields FOO, BAR, ID, NAME, and BAZ. If you don't have such a table
(and at least Oracle thinks "TABLE" is an invalid table name), it won't
work of course. You are supposed to replace the table name and field
names with the name and fields of a table which actually exists.

I don't understand how primary_key_info() gets into the picture. Do you
mean column_info?

hp


--=20
_ | Peter J. Holzer | If I wanted to be "academically correct",
|_|_) | Sysadmin WSR | I'd be programming in Java.
| | | hjp@wsr.ac.at | I don't, and I'm not.
__/ | http://www.hjp.at/ | -- Jesse Erlbaum on dbi-users

--LQksG6bCIzRHxTLp
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGyT2rMdFfQa64PCwRAusRAJ484gis+BGmFuYqzrtuBQYyPafm5wCf VTei
eXlsM8bgenRlMqPWNx8H/ko=
=CMaB
-----END PGP SIGNATURE-----

--LQksG6bCIzRHxTLp--