Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Graceful handling of DBI connect errors'

by Chief of Chaos (Friar)
on Nov 15, 2002 at 12:33 UTC ( [id://213127]=note: print w/replies, xml ) Need Help??


in reply to Graceful handling of DBI connect errors'

hi,
this is a code snippet from a bigger source.
But it will show you how might handle errors.
# ... # -------------------- # create db connection # -------------------- $dbase = DBI->connect("DBI:Oracle:$dbsid", $dbuser, $dbpassw, { Auto +Commit => 0 }); if (!(defined($dbase))){ # do error handling } # # ---------- # do the sql # ---------- # ... $dbase->{PrintError} = 0; $dbsth = $dbase->prepare( $sql ); $error = $dbase->errstr; if (defined ($error) && $error ne "") { # error handling # errormsg is stored in $error # ... $dbase->{set_err}=(0, ""); $dbase->{PrintError} = 1; # exit function or so # ... } else { # no error $dbase->{set_err}=(0, ""); $dbase->{PrintError} = 1; # ... } # ...
I hope this can help you.

Replies are listed 'Best First'.
Re: Re: Graceful handling of DBI connect errors'
by UnderMine (Friar) on Nov 15, 2002 at 13:07 UTC
    Carefull with auto commit turned off that causes its own fun...
    our $dbh = DBI->connect("DBI:Oracle:$dbsid", $dbuser, $dbpassw,{'AutoC +ommit'=>0}); our ($dbh_start, $dbh_error); # Global flags mutate during use of the +module sub start_trans() { my $proc = (caller(1))[3]; my $error; warn "Starting $proc\n"; if (not defined $dbh_start) { $dbh_start = $proc; } } sub end_trans() { my $proc = (caller(1))[3]; warn "Exiting $proc\n"; if ($dbh_start eq $proc) { if (not defined $dbh_error) { warn "Commited Transaction in $proc\n"; $dbh->commit; $dbh_error = undef; } else { warn "Rolled back Transaction in $proc\n"; warn "because $dbh_error\n"; $dbh->rollback; $dbh_error = undef; } $dbh_start = undef; } }
    Wrapper each atomic transaction in a sub procedure with :-
    start_trans(); ##### # SQL ##### end_trans()

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://213127]
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 2024-04-18 18:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found