Re: Perl error: fetchrow_hashref failed

From: Jeffrey <seesej(at)uswest(dot)net>
To: Moray McConnachie <moray(dot)mcconnachie(at)computing-services(dot)oxford(dot)ac(dot)uk>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Perl error: fetchrow_hashref failed
Date: 2000-04-12 11:57:43
Message-ID: B519B2C7.2CD4%seesej@uswest.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Your script works fine, but I still get the same error.

I can duplicate this same error with a non-hash ref like this.

$sth=$dbh->prepare("select param1,param2 from sometable");
$sth->execute;

while (($param1,$param2) = $sth->fetchrow_array) {
...... do something with them .
}

My concern is, does the error fetchrow_hashref or _array cause any problems
with the server, postmaster, postgres, etc. I am about to turn a site on
with lots of traffic and I don't want to crash because of these errors.

Thank you
js

> From: "Moray McConnachie" <moray(dot)mcconnachie(at)computing-services(dot)oxford(dot)ac(dot)uk>
> Date: Wed, 12 Apr 2000 12:45:42 +0100
> To: "Jeffrey" <seesej(at)uswest(dot)net>, " " <pgsql-general(at)postgresql(dot)org>
> Subject: Re: [GENERAL] Perl error: fetchrow_hashref failed
>
>
> ----- Original Message -----
> From: "Jeffrey" <seesej(at)uswest(dot)net>
> To: <pgsql-general(at)postgresql(dot)org>
> Sent: Wednesday, April 12, 2000 10:05 AM
> Subject: [GENERAL] Perl error: fetchrow_hashref failed
>
>
>> Hi, I wonder if I might tap the vast knowledge here againg.
>>
>> I have a perl script that is looping through a statement handle like this.
>>
>> $statement = "select * from sometable";
>> $sth=$dbh->prepare($statement);
>> $sth->execute();
>>
>> # here is the part I have a question about.
>> while (%hash_ref = %{$sth->fetchrow_hashref}) {
>>
>> while (($k,$v) = each (%hash_ref)) {
>> print ("\n$k == $v"); }
>> }
>
> I don't think your first loop will work because the %{$b} where $b is undef
> will not produce an undef - I think.
>
> See if this works? It ought to be more efficient anyway, because you only
> need one hash in my version, not two like your routine (that created by the
> fetchrow_hashref call and the hash %hashref itself.
>
> while (defined $hash_ref=$sth->fetchrow_hashref) {
> while (($k,$v)=each %$hashref) {
> print ("\n$k==$v");
> }
> }
>
>
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Urquhart 2000-04-12 12:16:08 Re: Can't load plpgsql.so error [SOLVED]
Previous Message Moray McConnachie 2000-04-12 11:45:42 Re: Perl error: fetchrow_hashref failed