AnyEvent-DBI
view release on metacpan or search on metacpan
has an associated server process that executes statements in order. If
you want to run more than one statement in parallel, you need to create
additional database handles.
The advantage of this approach is that transactions work as state is
preserved.
Example:
$dbh = new AnyEvent::DBI
"DBI:mysql:test;mysql_read_default_file=/root/.my.cnf", "", "";
Additional key-value pairs can be used to adjust behaviour:
=over 4
=item on_error => $callback->($dbh, $filename, $line, $fatal)
When an error occurs, then this callback will be invoked. On entry, C<$@>
is set to the error message. C<$filename> and C<$line> is where the
original request was submitted.
Timeout errors are always fatal.
=back
Any additional key-value pairs will be rolled into a hash reference
and passed as the final argument to the C<< DBI->connect (...) >>
call. For example, to suppress errors on STDERR and send them instead to an
AnyEvent::Handle you could do:
$dbh = new AnyEvent::DBI
"DBI:mysql:test;mysql_read_default_file=/root/.my.cnf", "", "",
PrintError => 0,
on_error => sub {
$log_handle->push_write ("DBI Error: $@ at $_[1]:$_[2]\n");
};
=cut
sub new {
my ($class, $dbi, $user, $pass, %arg) = @_;
handle has an associated server process that executes statements in
order. If you want to run more than one statement in parallel, you
need to create additional database handles.
The advantage of this approach is that transactions work as state is
preserved.
Example:
$dbh = new AnyEvent::DBI
"DBI:mysql:test;mysql_read_default_file=/root/.my.cnf", "", "";
Additional key-value pairs can be used to adjust behaviour:
on_error => $callback->($dbh, $filename, $line, $fatal)
When an error occurs, then this callback will be invoked. On
entry, $@ is set to the error message. $filename and $line is
where the original request was submitted.
If the fatal argument is true then the database connection is
shut down and your database handle became invalid. In addition
complicating recovery.
Timeout errors are always fatal.
Any additional key-value pairs will be rolled into a hash reference
and passed as the final argument to the "DBI->connect (...)" call.
For example, to suppress errors on STDERR and send them instead to
an AnyEvent::Handle you could do:
$dbh = new AnyEvent::DBI
"DBI:mysql:test;mysql_read_default_file=/root/.my.cnf", "", "",
PrintError => 0,
on_error => sub {
$log_handle->push_write ("DBI Error: $@ at $_[1]:$_[2]\n");
};
$dbh->on_error ($cb->($dbh, $filename, $line, $fatal))
Sets (or clears, with "undef") the "on_error" handler.
$dbh->timeout ($seconds)
Sets (or clears, with "undef") the database timeout. Useful to
( run in 0.246 second using v1.01-cache-2.11-cpan-05444aca049 )