Rolf,
        If need that much control over error messages, I'd leave
        RaiseError => 0 and handle status checking within the
        application.

        Also, a method I use to temporary change RaiseError is
        {
                local ($sth->RaiseError) = 0;
                ... my statement and stuff
        }
        
        e.g.
        {
                local ($sth->RaiseError) = 0;
                $dbh->do( q{drop table fred} );
        }

        When testing, the table fred may not exist.  So instead of the
        script bombing out, I localize the $sth handle in a block {}, change
        the value of RaiseError to 0, execute command(s), then when I 
        leave the block the localized $sth goes out of scope, perl handles
        the rest.

Tom

On Tue, Mar 06, 2001 at 05:15:29PM -0500, Kamp, Rolf F, ALSVC wrote:
> Hi:
>       I see the example in the Perl DBI book dealing with setting
> RaiseError OFF when connecting, then turning it ON in a block. I am trying
> to do the opposite, with no success.
>       I connect to the database with RaiseError ON:
> my $dbh = DBI->connect(undef, 'login', 'passwd', {RaiseError=>1}) or die
> ("Cannot connect to the database " . $DBI::errstr);
>       Then I have a bunch of DBI statements that I would like the program
> to croak on if an error occurs:
> 
> $usg_insert = $dbh->prepare(q{
> insert into usage(sid,interval,usage)
> values(?, to_date(?, 'MM-DD-YYYY-HH24:MI:SS'), ?)
> });
> $usg_update = $dbh->prepare(q{
> update usage set usage = usage + ?
> where sid = ? and interval = to_date(?, 'MM-DD-YYYY-HH24:MI:SS')
> });
> 
>       Then I have an insert that I would like to catch the error from,
> test if the insert failed for a violation of a unique constraint (duplicate
> row), then try an update:
> 
> if ($usg_select->fetch()) {
>   $dbh->{RaiseError} = 0;     # shut error catching OFF (can't get this
> right)
>   if (!$usg_insert->execute($sid, $startTimeForOracle, $tbytes)) {
>     $dbh->{RaiseError} = 1;   # turn error catching back on
>     print "INSERT OF USAGE FAILED $DBI::err $DBI::errstr\n";
>     if ($DBI::err == 1) {
>       if(!$usg_update->execute($tbytes, $sid, $startTimeForOracle)) {
>         print "usage update failed $DBI::err $DBI::errstr\n";
>       }
>     }
>   }
>   $dbh->{RaiseError} = 1;
> }
>       I cannot seem to get DBI to allow me to handle the failed insert.
> Any ideas or suggestions are greatly appreciated.
> 
> - Rolf.

-- 
Thomas A. Lowery        [EMAIL PROTECTED]
http://tlowery.hypermart.net

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

Reply via email to