|o||SQL error (a good reason to die).|
|o||Reconnect retries limit reached (database is completely down or network failure).|
If you are in transaction then even DB disconnect will raise an error. But you can check $dbh->is_trans_disconnect and restart the transaction if it is true. Other possible errors are the same: sql error and reconnect limit.
The recommended way of using transactions is
because txn_do would automatically restart the transaction if it was failed because of database disconnect. The transaction can be restarted at most TxnRetries times. If TxnRetries limit was reached then error would be raised and $dbh->is_fatal_trans_disconnect set to true. Other error cases are the same as above.
txn_do would try do to rollback if there was a perl or sql error (no rollback needed when you loose connection to database: DB server already has done it). Rollback is successul when $@ =~ /Rollback OK/;
DBIx::RetryOverDisconnects->connect($dsn, $user, $pass, $attrs);
All parameters are passed directly to DBI. Additional $attrs are
o ReconnectRetries - How many times DBIx::RetryOverDisconnects will try to reconnect to database. Default to 5. o ReconnectInterval - Interval (in seconds) between reconnect attemps. Default to 2. o ReconnectTimeout - Timeout (in seconds) for waiting the database to accept connection (because sometimes DBI->connect can block your application). Default to 5. o TxnRetries - How many times the wrapper would try to restart transaction if it was failed because of database connection problems. Default to 4.
$dbh->set_callback(afterReconnect => $code_ref);
Set callbacks for some events. Currently only afterReconnect is supported. It is called after every successful reconnect to database.
Return true if last failed operation was a transaction and it could be restarted. The database handle was successfuly reconnected again.
Return true if reconnect retries limit has been reached. In this case the database handle is not connected.
Return true if query failed because of some other reason, not related to database connection problems. See $DBI::errstr for details.
Always returns true or dies ($dbh->is_fatal_disconnect = true). Does original DBI::dbs ping and if it is false then it reconnects.
Executes $code_ref in a transaction environment. Automatically reconnects and restarts the transaction in any case of connection problems. txn_do is able to die with one of the is_fatal_disconnect, is_sql_error, is_fatal_trans_disconnect set to true.
In most cases you dont need to wrap it into eval because all of this exceptions are subject to die (database completely down, network down, bussiness logic error, etc).
prepare, do, statistics_info, begin_work, commit, rollback, selectrow_array, selectrow_arrayref, selectall_arrayref, selectall_hashref
execute, execute_array, execute_for_fetch
Currently PostgreSQL, MySQL, Oracle and SQLite are supported.
Pronin Oleg <firstname.lastname@example.org>
You may distribute this code under the same terms as Perl itself.
|perl v5.20.3||DBIX::RETRYOVERDISCONNECTS (3)||2012-10-19|