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=1):

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 == 1 - it was SQL error
   #If $DBIx::Safe::err == 2 - database connection was lost and all
connection retries were exceeded
}


Transaction usage:

while (1) {

   eval {
       $transactioncode->();
   }

    if ($@) {
       if ( $DBIx::Safe::err == 3 ) {
           #everything's okay; this is just a signal for restarting.
           next;
       }
       #Here, there is nothing you can do.
       #If $DBIx::Safe::err == 1 - it was SQL error (need to do rollback)
       #If $DBIx::Safe::err == 2 - all connection retries were exceeded
(doesn't need to rollback)
   }

}

Without RaiseError everything will be harder.

With RaiseError=0 And PrintError=0, 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.
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to