1 |
NAME |
2 |
AnyEvent::DBI - asynchronous DBI access |
3 |
|
4 |
SYNOPSIS |
5 |
use AnyEvent::DBI; |
6 |
|
7 |
DESCRIPTION |
8 |
This module is an AnyEvent user, you need to make sure that you use and |
9 |
run a supported event loop. |
10 |
|
11 |
This module implements asynchronous DBI access my forking or executing |
12 |
separate "DBI-Server" processes and sending them requests. |
13 |
|
14 |
It means that you can run DBI requests in parallel to other tasks. |
15 |
|
16 |
The overhead for very simple statements ("select 0") is somewhere around |
17 |
120% to 200% (single/dual core CPU) compared to an explicit |
18 |
prepare_cached/execute/fetchrow_arrayref/finish combination. |
19 |
|
20 |
METHODS |
21 |
$dbh = new AnyEvent::DBI $database, $user, $pass, [key => value]... |
22 |
Returns a database handle for the given database. Each database |
23 |
handle has an associated server process that executes statements in |
24 |
order. If you want to run more than one statement in parallel, you |
25 |
need to create additional database handles. |
26 |
|
27 |
The advantage of this approach is that transactions work as state is |
28 |
preserved. |
29 |
|
30 |
Example: |
31 |
|
32 |
$dbh = new AnyEvent::DBI |
33 |
"DBI:mysql:test;mysql_read_default_file=/root/.my.cnf", "", ""; |
34 |
|
35 |
Additional key-value pairs can be used to adjust behaviour: |
36 |
|
37 |
on_error => $callback->($dbh, $filename, $line, $fatal) |
38 |
When an error occurs, then this callback will be invoked. On |
39 |
entry, $@ is set to the error message. $filename and $line is |
40 |
where the original request was submitted. |
41 |
|
42 |
If this callback returns and this was a fatal error ($fatal is |
43 |
true) then AnyEvent::DBI die's, otherwise it calls the original |
44 |
request callback without any arguments. |
45 |
|
46 |
If omitted, then "die" will be called on any errors, fatal or |
47 |
not. |
48 |
|
49 |
$dbh->exec ("statement", @args, $cb->($rows, %extra)) |
50 |
Executes the given SQL statement with placeholders replaced by |
51 |
@args. The statement will be prepared and cached on the server side, |
52 |
so using placeholders is compulsory. |
53 |
|
54 |
The callback will be called with the result of "fetchall_arrayref" |
55 |
as first argument and possibly a hash reference with additional |
56 |
information. |
57 |
|
58 |
If an error occurs and the "on_error" callback returns, then no |
59 |
arguments will be passed and $@ contains the error message. |
60 |
|
61 |
SEE ALSO |
62 |
AnyEvent, DBI. |
63 |
|
64 |
AUTHOR |
65 |
Marc Lehmann <schmorp@schmorp.de> |
66 |
http://home.schmorp.de/ |
67 |
|