Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Baffled by "fetchrow_hashref failed: no statement executing"

by hesco (Deacon)
on Jul 06, 2009 at 00:36 UTC ( [id://777414]=perlquestion: print w/replies, xml ) Need Help??

hesco has asked for the wisdom of the Perl Monks concerning the following question:

The query dumped into my log runs fine at a psql> prompt, returning anticipated data. I don't know that I have ever encountered this "fetchrow_hashref failed: no statement executing" error before.

My code looks like this:

sub _get_billing_plan_options { my $self = shift; my @billing_plan_options; my $sql = $self->{'cfg'}->param("sql.get_svc_plan_options"); $self->log('DEBUG','->_get_billing_plan_options() says our query is: + ' . $sql); my $sth = $self->{'dbh'}->prepare($sql); $self->log('DEBUG','Our $sth is: ',$sth); while (my $options = $sth->fetchrow_hashref()){ $options->{'plan_type'} =~ s/_/ /; push @billing_plan_options, [ 'service_plan_' . $options->{'svc_pl +an_id'}, $options->{'plan_name'}, $options->{'plan_type'} ]; push @billing_plan_options, [ 'service_plan_prepay_' . $options->{ +'svc_plan_id'}, $options->{'plan_name'}, $options->{'plan_type'} ]; } return \@billing_plan_options; }
My logs report:

DEBUG: ->_get_billing_plan_options() says our query is: SELECT svc_pla +n_id, plan_name, plan_type FROM svc_plans WHERE plan_active ORDER BY +plan_type, plan_sort_order DEBUG: Our $sth is: $VAR1 = bless( {}, 'DBI::st' ); Uncaught exception from user code: DBD::Pg::st fetchrow_hashref failed: no statement executing
Any pointers would be appreciated.

-- Hugh

UPDATE:

Yes, of course. Perhaps I should have taken the evening off instead of trying to code on a Sunday evening. A bit of rest might help me avoid overlooking the obvious. Thank you, jrsimmon, for the second set of eyes on this. I guess next time I will recognize that unfamiliar error message.

if( $lal && $lol ) { $life++; }

Replies are listed 'Best First'.
Re: Baffled by "fetchrow_hashref failed: no statement executing"
by jrsimmon (Hermit) on Jul 06, 2009 at 00:50 UTC
    The flow for a dbi query that returns data is:
    1. Define statement
    2. Prepare statement
    3. Execute statement
    4. Fetch results of statement

    You're missing step 3. You're code should look like this:
    sub _get_billing_plan_options { my $self = shift; my @billing_plan_options; my $sql = $self->{'cfg'}->param("sql.get_svc_plan_options"); $self->log('DEBUG','->_get_billing_plan_options() says our query is: + ' . $sql); my $sth = $self->{'dbh'}->prepare($sql); $self->log('DEBUG','Our $sth is: ',$sth); #you have to execute the prepared query! $sth->execute(); while (my $options = $sth->fetchrow_hashref()){ $options->{'plan_type'} =~ s/_/ /; push @billing_plan_options, [ 'service_plan_' . $options->{'svc_pl +an_id'}, $options->{'plan_name'}, $options->{'plan_type'} ]; push @billing_plan_options, [ 'service_plan_prepay_' . $options->{ +'svc_plan_id'}, $options->{'plan_name'}, $options->{'plan_type'} ]; } #Don't forget to finish the statement handle $sth->finish; return \@billing_plan_options; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://777414]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-18 14:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found