DBD-Oracle icon indicating copy to clipboard operation
DBD-Oracle copied to clipboard

sth handle lost

Open lihai2099 opened this issue 3 years ago • 1 comments

My code:

 $sth = $dbh->prepare($sql);
  $sth->execute();
  while(my @tmp = $sth->${fetch_type}()){
        if($interrupt){$sth->finish;$interrupt=0;return 2};
        for my $i(0..$#alias_title){
                my $val_size = length($tmp[$i]);
                $col_size{$alias_title[$i]} = $val_size if($val_size > $col_size{$alias_title[$i]});
        }
        $rows += 1;
        push @result,join('`',@tmp);
        last if($rows > $pre_rows);
  }
if($rows>0){
        for(@result){
                if($interrupt){$sth->finish;$interrupt=0;return 2};
                my @tmp = split('\`',$_,-1);
                printf("$fmt\n",@tmp);
               # print "---------------- $paging --------------\n";
                $paging++;
        }
        if($sth){
                while(my @line = $sth->${fetch_type}()){    ### This is the line which course the error.
                        if($interrupt){$sth->finish;$interrupt=0;return 2};
                        printf("$fmt\n",@line);
                      #  print "---------------- $paging --------------\n";
                        $paging++;
                }
                $rows += 1 ;
        }

=============================================================== If the input sql is "select * from dba_tables where rownum<10;" ,everything is OK.But if the input sql is "select * from dba_tab_columns where rownum<10;",An error appear: DBD::Oracle::st fetchrow failed: ERROR no statement executing (perhaps you need to call execute first) [for Statement "select * from dba_tab_columns where Table_Name='ORDDCM_PRV_ATTRS_WRK'"] at dbi.pl line 203, line 16.

I hava try others tables,for example,dba_objects ,the error does not appear. It seems only the table with table name "dba_tab_columns" will causes the errors;

I analyse the problem,guess the db handle $sth have lose when execut the code : "while(my @line = $sth->${fetch_type}()){ " But I done not know how to reslove.

perl version:v5.16.3 DBD-Oracle VERSION:1.82 dbi version:1.643 Can somebody help me ?

lihai2099 avatar Oct 21 '22 09:10 lihai2099

It looks like it's because you are called $sth->finish but then try to reuse it with $sth->${fetch_type}.

https://metacpan.org/pod/DBI#finish

whindsx avatar Oct 27 '22 20:10 whindsx