DBItransaction
- Class to handle transactions on a DBI-instance.
use DBItransaction;
# DBI instance
my $dbi=DBI->new(SOME_INIT....);
# create instance
my $t=DBItransaction->new($dbi);
# create instance with error values set in a class instances data
my $t=DBItransaction->new($dbi,$instance);
Class to handle transactions on a DBI-instance. If nested, the outmost instance will own the transaction. mine() will reflect ownership to the transaction.
On end() (called implicitely from DESTROY) a rollback() will be run if commit() fails.
commit() fails if $DBItransaction::DBItransaction{rollingback} is true or DBI->err is true and rollbackonerror() is true or mine() and DBI->commit fails
rollback() do a DBI->rollback if mine(), otherwise it signals a rollback by setting $DBItransaction::DBItransaction{rollingback} to true;
A signalled rollback can be cancelled by cancelrollback() if the problem is resolved.
Instantiates the DBItransaction class.
It takes one parameter:
DBI The DBI-instance that one is performing transactions on. Required.
Returns the DBItransaction instance upon success.
Returns if the commit belongs to this DBItransaction instance or not.
The return can be moderated by the inhibit()-method. See the inhibit()-method for more information.
Inhibits committing changes even if this instance of DBItransaction owns the commit/started the transaction.
No accepted input to this method.
No return from this method.
Commits the transactional record.
This is only done if this instance of DBItransaction owns the commit/started the transaction (see the mine()-method).
It also not done if a rollback is already in progress for some reason.
Returns 1 upon success, 0 upon failure.
Please check the commiterr()-method for more information upon failure. Or in the case of automatic DBItransaction-DESTROY upon end of a function or block and the err-option was set on instantiation, the error will be found in the err-instance (see the new()-method).
Set the commit error.
Input is the error-string as a SCALAR.
No return from method.
This is an internal method and is not to be called by user.
Gets the commit error.
No input accepted.
The return is the commit error SCALAR (if any).
Attempts to run a rollback of the transactional record of the DBI-instance.
Optional input is the reason for the rollback.
It will only attempt a rollback if the DBItransaction-instance in question own the commit/start of the transaction (see the mine()-method). If the transaction is not "mine" a rollback request is signalled by detting the package global $DBItransaction{rollingback} to true (reason || 1);
It returns 1 upon success, 0 upon failure.
Please check the rollbackerr()-method for more information upon failure.
Sets/get rollbackonerror policy. If rollbackonerror is set on this DBItransaction object, a rollback is attempted/signalled on $trancsaction->end (or DESTROY).
b<boolean> Optional parameter to set rollbackonerror status.
Optional input is a boolen. If defined, sets the rollbackonerror option to the indicated value. On end() (or DESTROY()) rollback(DBI->errstr) is called if DBI->err;
Returns the rollbackonerror flag if given without parameter. With parameter it returns $self.
Returns the rollingback flag of the err-option.
See the new()-method for more information on the err-option.
Removes the rollingback flag of the err-option.
See the new()-method for more information on the err-option.
Sets the rollback error.
Input is the rollback error as a SCALAR.
It has no return.
See the rollbackerr()-method for information on getting the rollback-error. This is an internal method and should not be called by the user.
Gets the rollback error message.
It has no accepted input.
Returns the rollback error message as a SCALAR.
See the err-option of the new()-method for more information on the location of error-messages.
If mine() Attempts to commit transaction or rollback if any error.
No input is accepted.
Returns the output from method commit() or rollback(). A commit or a rollback will only be performed if this instance owns the commit/start of the transaction and it has not been inhibited (see the mine()- and inhibit()-methods).
Clears the instance commit error, cancels any rollback and enables inhibiting of commits.
No input accepted and no return value.
Handles de de-instantiation of the DBItransaction instance.
It de-instantiates the DBItransaction-instance by calling the end()-method. See the end()-method for more information.
It will basically automatically handle commits and rollback for you, even when the DBItransaction instance is being destroyed by a function- exit or end of a block.
AUTOLOAD-handler.
Makes it possible to call any DBI-method on the DBItransaction instance and thereby using it as a class that has inherited from the DBI-class.
See Autoloading in perlsub in the Perl documentation for more information on the AUTOLOAD mechanism.
Hey! The above document had some coding errors, which are explained below:
'=item' outside of any '=over'
=cut found outside a pod block. Skipping to next block.
You forgot a '=back' before '=head2'