… | |
… | |
2 | AnyEvent::DBI - asynchronous DBI access |
2 | AnyEvent::DBI - asynchronous DBI access |
3 | |
3 | |
4 | SYNOPSIS |
4 | SYNOPSIS |
5 | use AnyEvent::DBI; |
5 | use AnyEvent::DBI; |
6 | |
6 | |
|
|
7 | my $cv = AnyEvent->condvar; |
|
|
8 | |
|
|
9 | my $dbh = new AnyEvent::DBI "DBI:SQLite:dbname=test.db", "", ""; |
|
|
10 | |
|
|
11 | $dbh->exec ("select * from test where num=?", 10, sub { |
|
|
12 | my ($rows, $rv) = @_; |
|
|
13 | |
|
|
14 | print "@$_\n" |
|
|
15 | for @$rows; |
|
|
16 | |
|
|
17 | $cv->broadcast; |
|
|
18 | }); |
|
|
19 | |
|
|
20 | # asynchronously do sth. else here |
|
|
21 | |
|
|
22 | $cv->wait; |
|
|
23 | |
7 | DESCRIPTION |
24 | DESCRIPTION |
8 | This module is an AnyEvent user, you need to make sure that you use and |
25 | This module is an AnyEvent user, you need to make sure that you use and |
9 | run a supported event loop. |
26 | run a supported event loop. |
10 | |
27 | |
11 | This module implements asynchronous DBI access my forking or executing |
28 | This module implements asynchronous DBI access by forking or executing |
12 | separate "DBI-Server" processes and sending them requests. |
29 | separate "DBI-Server" processes and sending them requests. |
13 | |
30 | |
14 | It means that you can run DBI requests in parallel to other tasks. |
31 | It means that you can run DBI requests in parallel to other tasks. |
15 | |
32 | |
16 | The overhead for very simple statements ("select 0") is somewhere around |
33 | The overhead for very simple statements ("select 0") is somewhere around |
17 | 120% to 200% (single/dual core CPU) compared to an explicit |
34 | 120% to 200% (dual/single core CPU) compared to an explicit |
18 | prepare_cached/execute/fetchrow_arrayref/finish combination. |
35 | prepare_cached/execute/fetchrow_arrayref/finish combination. |
19 | |
36 | |
20 | METHODS |
37 | METHODS |
21 | $dbh = new AnyEvent::DBI $database, $user, $pass, [key => value]... |
38 | $dbh = new AnyEvent::DBI $database, $user, $pass, [key => value]... |
22 | Returns a database handle for the given database. Each database |
39 | Returns a database handle for the given database. Each database |
… | |
… | |
44 | request callback without any arguments. |
61 | request callback without any arguments. |
45 | |
62 | |
46 | If omitted, then "die" will be called on any errors, fatal or |
63 | If omitted, then "die" will be called on any errors, fatal or |
47 | not. |
64 | not. |
48 | |
65 | |
49 | $dbh->exec ("statement", @args, $cb->($rows, %extra)) |
66 | $dbh->exec ("statement", @args, $cb->($rows, $rv, ...)) |
50 | Executes the given SQL statement with placeholders replaced by |
67 | Executes the given SQL statement with placeholders replaced by |
51 | @args. The statement will be prepared and cached on the server side, |
68 | @args. The statement will be prepared and cached on the server side, |
52 | so using placeholders is compulsory. |
69 | so using placeholders is compulsory. |
53 | |
70 | |
54 | The callback will be called with the result of "fetchall_arrayref" |
71 | The callback will be called with the result of "fetchall_arrayref" |
55 | as first argument and possibly a hash reference with additional |
72 | as first argument (or "undef" if the statement wasn't a select |
56 | information. |
73 | statement) and the return value of "execute" as second argument. |
|
|
74 | Additional arguments might get passed as well. |
57 | |
75 | |
58 | If an error occurs and the "on_error" callback returns, then no |
76 | If an error occurs and the "on_error" callback returns, then no |
59 | arguments will be passed and $@ contains the error message. |
77 | arguments will be passed and $@ contains the error message. |
60 | |
78 | |
61 | SEE ALSO |
79 | SEE ALSO |