Re: hashes
by Bodo Eing other posts by this author
Oct 19 2000 11:15AM messages near this date
RE: hashes
|
Oracle database usergroup or mailing list reqd.
Date sent: Thu, 19 Oct 2000 12:45:50 +0400
From: Xen <xen_ua@[...].com>
Send reply to: "Kashkin, Mikhail " <MKashkin@[...].ru>
Organization: Mary Kay
To: DBI Users <dbi-users@[...].org>
Subject: hashes
Mikhail, you wrote:
> Hello DBI,
>
> Anybody know how i can recognize name of column from query or
> (better) get it as hash. Of course results be unique only in one
> column.
>
> Example:
>
> SQL - "select name_30, access as Name from users"
>
> name - unique
> access [1,2,3]
>
> while(my(%res) = $sec->fetchrow) {
> %res{'Name'}....
> }
>
> Big thanks.
Use the fetchrow_hashref method like this:
Connect, prepare and execute your SQL statement, then:
while ( my $rec = $sth-> fetchrow_hashref ) {
my %current_record = % $rec;
print $current_record{'Name'}; # or whatever else
}
I believe that there was a way of directly accessing the hash
without explicitly dereferencing it before, but I don't remember it at
the moment. Additionally, I prefer to push all the hashrefs onto an
array and process this later, so processing of the retrieved data
does not interfere with fetching itself.
HTH
Bodo Eing
eingb@[...].de
Dr. med. Bodo Eing
Institut fuer Medizinische Mikrobiologie
Klinische Virologie
v.-Stauffenbergstr. 36
48151 Muenster
Germany
Phone: ++49 251 7793 111 Fax: ++49 251 7793-104
------------------------------------------------------------------------------
DBI HOME PAGE AND ARCHIVES: http://www.symbolstone.org/technology/perl/DBI/
To unsubscribe from this list, please visit: http://www.isc.org/dbi-lists.html
If you are without web access, or if you are having trouble with the web page,
please send mail to dbi-users-request@[...].org with the subject line of:
'unsubscribe'.
------------------------------------------------------------------------------
Thread:
Xen
Sumit Babu
Bodo Eing
|