PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Matthew dot Persico at Lazard dot com
Subject: Getting warning "no statement executing" Why?
Date: Oct 3 2002 2:27PM

I am occasionally (not reproducible) getting this error:

no statement executing at /am/clrpt/lib/site_perl/5.6.1/Portia/Utils.pm line
435.

I get this statement about two or three times and then the next execution just
hangs. The process has to be terminated.  A section of the relevant code is
listed below. Line 435 is commented for your perusal.

***
** Question #1: Can anyone explain under what circumstances this can happen?
***

You will notice that the prepare and execute are error-checked (using eval and
$@ analysis) and that I am checking the return value from the fetchrow_hashref
call.

***
** Question #2: Is there anything else I should be doing error-checking-wise
** that I am not currently doing?
**

I think this warning is coming from dbdimp.c (DBD::Sybase 0.94):

2399      /* Check that execute() was executed sucessfully. This also implies */
2400      /* that describe() executed sucessfuly so the memory buffers        */
2401      /* are allocated and bound.                                         */
2402      if ( !DBIc_is(imp_sth, DBIcf_ACTIVE) || !imp_sth->exec_done ) {
2403          warn("no statement executing");
2404          return Nullav;
2405      }

Now, I can amend my code at line 435 to bark loudly if I get no results from the
fetchrow_hashref calling by checking that
scalar(@retVal) > 0, but what I'd RATHER do is make that warning be a fatal,
since no rows fetched is an OK result that can be handled by the caller of this
routine. That leads to question #3:

***
** Question #3: How can I trap this in my code?
***

I am in perl 5.6.1 so I could try this:

a) Turn up the warnings:

{
    ## Lexically scoped use pragma limited to these braces
    use warnings FATAL => qw/all/;
    while ($rh_row = $sth->fetchrow_hashref()) { ##### Line 435
            my %rowCopy = %{$rh_row};
            push @retVal, \%rowCopy;
        }
}

But I do not think this will work because the warning that is used in
DBD::Sybase is not part of the 'use warnings' hierarchy. (Maybe, we might want
to patch DBD::Sybase to register its warnings. See "Reporting Warnings from a
Module" in perldoc perllexwarn).

Failing that, there's this old standby:

b) Use a local WARN handler:

eval {
    local $SIG{__WARN__} =
    sub {
     die $_[0] if $_[0] =~ /no statement executing/;
     warn $_[0];
    }
    while ($rh_row = $sth->fetchrow_hashref()) { ##### Line 435
        my %rowCopy = %{$rh_row};
        push @retVal, \%rowCopy;
    }
};
if($@ || $sth->err()) {
    if($@ =~ /no statement executing/) {
        ## do something specific to this error
    } else {
        ## do generic error handling
    }
}

I think I need to do option b. Any other suggestions for trapping and/or
diagnosis of the underlying problem?

Thanks.
--
Matthew Persico
Vice President
Lazard
30 Rockefeller Plaza
New York, NY 10020, USA
Phone Number: 212 632 8255
Fax Number: 212 332 5904
Email: matthew.persico@lazard.com

***
** Code fragment:
**

###
## $ldbh, the database handle, is passed into this routine

## The sql is dynamically built, but the basis for the sql is:
## select pmf_id = id
##        ,symbol = symbol
##        ,portfolio = portfolio
##        ,account_no = pmf_string_06
##        ,fiscal_begin = convert(varchar,fiscal_begin,101)
##        ,acct_period_end = acct_period_end
##        ,live_on_portia = convert(varchar,pmf_date_03,101)
##        ,live_on_portia_plus = convert(varchar,pmf_date_04,101)
## from   pmf
## where  system_stat = 0
## and    symbol = '%s'
## order  by pmf_id desc

my $sth = undef;
eval {
    $sth = $ldbh->prepare($sql);
};
if($@ || $ldbh->err()) {
    confess LogTextForDie("Some big string here");
}
$sth->{private_AMG_DBI_data} = {
                    DBMS => $ldbh->{private_AMG_DBI_data}->{DBMS},
                       handleType => "statement",
                       sql => $sql
                       };

####
## Execute query
eval {
    $sth->execute();
};

if($@ || !$sth || $ldbh->err()) {
    confess LogTextForDie("Some big string here");
}

####
## Get results
my @retVal = ();
my $rh_row = undef;
while ($rh_row = $sth->fetchrow_hashref()) { ##### Line 435
    my %rowCopy = %{$rh_row};
    push @retVal, \%rowCopy;
}

## Clean up statement handle
$sth->finish();