On Tue, 16 May 2000, William Deegan wrote:

> Greetings,
> 
> from the various perldocs and web pages I understand the following
> to be true.
> 
> If autocommit is not set and a script exits the transaction will be
> rolled
> back.
> 
> The question I have is when the database handle is re-used will the
> autocommit still be unset if the script that set it errors out?

No. What you need to do is use an exception handler around your code (see
the guide/perl.html) and commit if your code ran OK, or rollback if
not. Here's how I do it (sort of - there's more code to it than this):

eval {
        dispatch();
};
if ($@) {
        rollback;
        output('errorpage.template', $@->value);
        return OK;
}

return OK;

However also ensure that your transaction handling is fine grained at the
level its happening. I use DBIx::AnyDBD so that I can do this:

$db->begin_tran;

$db->do_stuff; # calls die() if it fails

# non-db stuff that calls die() if it fails

$db->commit;

-- 
<Matt/>

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org http://xml.sergeant.org

Reply via email to