Sometimes the following code is giving a "fetchrow_hashref failed: fetch() without execute()" error. How is it possible, given the execute()'s position within the if()? Thanks for any advice.
my $sth = $db->{ 'dbh' }->prepare( $sql );
if ( $sth->execute() ) {
my @rows = ();
while ( my $ref = $sth->fetchrow_hashref() ) {
push @rows, $ref;
}
return @rows;
}
UPDATE: The problem was found - that $sth->execute() returns -1 on a deadlock, which is boolean true and so the fetchrow_hashref() runs. We need to check for a return code less than zero.