Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: DBI HandleError statement display

by tommyw (Hermit)
on Aug 07, 2002 at 09:58 UTC ( [id://188272]=note: print w/replies, xml ) Need Help??


in reply to DBI HandleError statement display

The DBI documentation includes $sth->Statement which will give you the text passed to prepare. If you can work out which statement handle to use :(

Or there's the ShowErrorStatement attribute, which might do what you want, without needing a custom error handler:

"ShowErrorStatement" (boolean, inherited) NEW
This attribute can be used to cause the relevant Statement text to be appended to the error messages generated by the "RaiseError" and "PrintError" attributes. Only applies to errors on statement handles plus the prepare(), do(), and the various "select*()" database handle methods. (The exact format of the appended text is subject to change.)

--
Tommy
Too stupid to live.
Too stubborn to die.

Replies are listed 'Best First'.
Re: Re: DBI HandleError statement display
by axelrose (Scribe) on Aug 07, 2002 at 10:58 UTC
    Thanks for your reply, Tommy!

    I tried "$dbh->{ShowErrorStatement} =1" as well as "$inssth->{ShowErrorStaement = 1" without any visible change in the error message.

    The statement handles are indeed varying so I cannot use "$sth->Statement".

    Some improvement though gives:
    $dbh->{HandleError} = sub { warn $DBI::lasth->{Statement}; Carp::confess; }
    Now the error messages looks like:
    insert into mytable values ( ?, ? ) main::__ANON__('DBD::Oracle::st execute failed: ORA-01722: ...
    I found a message from Tim Bunce in perl.dbi.dev that he is planning an extension for showing the bound parameters as well. That means for the moment I'm stuck unless I give up the placeholders.
      Tommy, have you tried using $dbh->trace? Not sure what your application is doing, but if you're trying to insert invalid data, hopefully that means that you just haven't beefed up your edits enough yet. Use $dbh->trace to help figure out what "bad" data you're trying to insert, then beef up your edits to prevent that data from making it that far. I could swear that I've used Carp's cluck before and gotten a meaningful stack trace that *did* show the placeholder values trying to get inserted(or updated, whatever).

      HTH.

        Thanks for the hint. Yes, I found the culprit by using $dbh->trace(2).

        Nonetheless I wonder what the best *general* solution for reporting errors looks like.

      $dbh->{ShowErrorStatement}=1 before the prepare() should certainly work. Please double check and post a trace() extract to dbi-users if you can't fix it. Placeholder values will be shown if ShowErrorStatement is true _and_ the driver supports the new ParamValues attribute (few do yet). Tim.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2025-05-23 15:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.