RE: Retrieving data from Oracle

[email protected] ("Markiewicz, Andrew") Wed, 1 Jun 2005 11:02:06 -0500
Newsgroups perl.dbi.oracle-oci
Message-ID <[email protected]>
One additional thing I noticed.
The fetchrow_hashref currently returns a different reference each time it is
executed.  So looping through and pushing the references in a list works
fine for now.  But from the perldoc DBI:

         "Currently, a new hash reference is returned for each
         row.  This will change in the future to return the same
         hash ref each time, so don't rely on the current
         behaviour."

Your code relies on the fact that the references are different for each
call.
When/if the DBI module is changed to return the same reference, your code
will break since it will store a list of all the same hash reference, all
pointing to your last row in the cursor.

To continue using an array of hash references, copy the hash results into an
anonymous hash reference and push that reference on the array.


   while ($row = $sth->fetchrow_hashref()) {
     push (@list,$row);		# original
     push (@list,{%$row});	# new reference
   }

You can check both hex addresses of the references to verify that they are
different.

-----Original Message-----
From: Sangeeth V S [mailto:[email protected]] 
Sent: Wednesday, June 01, 2005 4:32 AM
To: Markiewicz, Andrew
Subject: Re: Retrieving data from Oracle


Sent by mailto:[email protected]
______________________________________________

Hi Andrew,

$sth->fetchrow_hashref('NAME_lc') worked for me! Thanks for the help.

Sangeeth



----- Original Message ----- 
From: "Markiewicz, Andrew" <[email protected]>
To: <[email protected]>; <[email protected]>
Sent: Tuesday, May 31, 2005 8:53 PM
Subject: RE: Retrieving data from Oracle


> I use fetchrow_hashref with Oracle successfully.
>
> Try specifying the case of the columns (uc or lc depending on 
> preference
or
> current usage in the program):
> $sth->fetchrow_hashref('NAME_lc')
>
>
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> Sent: Tuesday, May 31, 2005 9:36 AM
> To: [email protected]
> Subject: Retrieving data from Oracle
>
>
> Sent by 
> mailto:[email protected]
> __________________________________________________________
>
> Hi,
>
> I'm migrating a perl application in postgres to Oracle.  Here, the 
> data is being retrieved as below.
>
>   while ($row = $sth->fetchrow_hashref()) {
>     push (@list,$row);
>   }
>
> It looks like fetchrow_hashref() is not working with Oracle.  But I'm 
> able to retrieve the data through fetchrow_array.  Any idea why
> fetchrow_hashref() is not working?  Is there any other alternative for 
> fetchrow_hashref()?  How do I accomplish the above with any other 
> fetch methods?
>
> Thanks in advance.
>
> Sangeeth
>