Re: Help: error not clearing from one call to the next?



That's odd. You've not stated the DBI or DBD::Oracle versions.

Try using trace (level 4) with a recent version of the DBI
to see what the DBI thinks is happening to the error status.

Tim.

On Thu, Apr 21, 2005 at 09:03:54AM -0700, Joel Stevenson wrote:
> Hi all,
>
> I'm running into an interesting problem with a database error that
> occurs on one statement handle and seems to affect another handle
> despite using eval {...} and RaiseError. Perhaps example code would
> be describe the situation:
>
> my $attr = {RaiseError => 1};
> my $dbh = DBI->connect ('dbi:mysql:','user','pass', $attr);
>
> my $topSTH = $dbh->prepare ("SELECT NAME FROM FOO");
> $topSTH->execute ();
>
> while (my $hashRef = $topSTH->fetchrow_hashref ()) {
>
> # do stuff here
>
> eval {
> my $inSTH = $dbh->prepare ("SELECT SOMEVALUE FROM MYMAYBETABLE
> WHERE ID=1");
> $inSTH->execute ();
>
> my ($value) = $inSTH->fetchrow_array ();
> # do something with value
> };
> if ($@) {
> print STDERR "ERR: $@";
> }
>
> }
>
>
>
> MYMAYBETABLE is a table that may or may not exist and because of that
> I wrapped the prepare/execute in an eval. When the table does not
> exist the error is caught and handled as expected (the "ERR: $@" line
> is printed to STDERR) but for some reason the next iteration of the
> while loop throws exactly the same error from the
> $topSTH->fetchrow_hashref call even though it is not touching
> MYMAYBETABLE at all. So I get "DBD::mysql::st fetchrow_hashref
> failed: Table 'MYMAYBETABLE' doesn't exist at ..." being thrown from
> both $inSTH and $topSTH !?
>
> So it seems like the error that occurred in $inSTH is being held onto
> and affecting other statement handles created from the same database
> handle.
>
> I've been looking through the list archives but as yet haven't found
> anything about this. Is this expected behavior? If so, how can I
> clear the error so that the top while loop can continue on after such
> an error?
>
> TIA,
> Joel
.



Relevant Pages

  • Re: Counting help
    ... time through the loop, that should fix your immediate problem. ... broken the DBI steps into prepare/execute. ... support some sort of counting ability. ...
    (perl.beginners)
  • Re: escaping @
    ... Only do things in the loop that must be done in the loop. ... Reconnecting, ... perldoc DBI ... close INFILE; ...
    (perl.beginners)
  • bizarre fetchrow_hashref error
    ... either in the DBI or DBD::Oracle documentation or via ... I have a script that runs in a loop, reading data files (usually ... ..xls or .csv) with financial timeseries data and inserting the data into ...
    (perl.dbi.users)
  • Re: Perl DBI - How to handle large resultsets?
    ... > to the queries because I edited that out. ... This line is probably better outside the while loop; ... Again, as Xho suggests, finishshould not be called on $repo_sth. ... while loop should have eaten up the result set and caused DBI to call ...
    (comp.lang.perl.misc)
  • Re: How to turn $_ into a hashref?
    ... Philip, thank you very much. ... If I don't need or want DBI handle attributes, how can I define a null hash reference? ... the how point of using bind values is you should $dbh->prepare ... then $sth->executein the loop. ...
    (perl.beginners)