[Dbix-class] DBIx::Safe. DBI wrapper.
Oleg Pronin
syber.rus at gmail.com
Fri May 11 11:53:09 GMT 2007
I've commited pre-alpha version :)
( http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Safe )
Sorry, no POD yet.
It is used as ordinary DBI class.
The additional params to $attrs when DBI->connect are:
SafeRetries - Number of retries for reconnection
SafeInterval - Interval in seconds between retries
SafeTimeout - If firewall or anything else hangs 'connect' call then this is
a timeout for connect operation.
Basic Usage is simple (with RaiseError=3D1):
When not in transaction:
just $dbh->prepare or $sth->execute, etc.
In normal case there will be always success (except for critical
situations).
To handle these critical situations:
eval {
$dbh->prepare;
$sth->execute;
$dbh->selectall_arrayref ;
<whatever>
};
if ($@) {
#If you get here, there is nothing you can do with that requests
anymore.
#If $DBIx::Safe::err =3D=3D 1 - it was SQL error
#If $DBIx::Safe::err =3D=3D 2 - database connection was lost and all
connection retries were exceeded
}
Transaction usage:
while (1) {
eval {
$transactioncode->();
}
if ($@) {
if ( $DBIx::Safe::err =3D=3D 3 ) {
#everything's okay; this is just a signal for restarting.
next;
}
#Here, there is nothing you can do.
#If $DBIx::Safe::err =3D=3D 1 - it was SQL error (need to do rollba=
ck)
#If $DBIx::Safe::err =3D=3D 2 - all connection retries were exceeded
(doesn't need to rollback)
}
}
Without RaiseError everything will be harder.
With RaiseError=3D0 And PrintError=3D0, DBIx::Safe will be silent. Only
$DBIx::Safe::err could be usefull.
(Maybe it is okay for offline-scripts which don't use transactions ?). But i
prefer to always use RaiseError.
There will be $dbh->txn_do method (currently it is empty) which is similar
to "Transaction usage:" code.
Unfortunately, DBIx::Safe do not clear errstr, err after successfull calls.
It is alpha version. It slows down the DBI by about 70-80% ("do" needs 80%
more time, prepare - about 40%).
But if it will be ok i apply perfomance hooks which would decrease
perfomance loss to about 10-20%.
The main problem is that getting DBI's attributes is amazingly slow!
even getting the class variable $DBI::errstr is very slow!
I would be cool to write the same in XS.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070511/67f=
ebd90/attachment.htm
More information about the Dbix-class
mailing list