ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-DBI/DBI.pm
(Generate patch)

Comparing AnyEvent-DBI/DBI.pm (file contents):
Revision 1.6 by root, Thu Jun 12 11:56:59 2008 UTC vs.
Revision 1.7 by root, Mon Jul 21 02:34:40 2008 UTC

9 my $cv = AnyEvent->condvar; 9 my $cv = AnyEvent->condvar;
10 10
11 my $dbh = new AnyEvent::DBI "DBI:SQLite:dbname=test.db", "", ""; 11 my $dbh = new AnyEvent::DBI "DBI:SQLite:dbname=test.db", "", "";
12 12
13 $dbh->exec ("select * from test where num=?", 10, sub { 13 $dbh->exec ("select * from test where num=?", 10, sub {
14 my ($rows) = @_; 14 my ($rows, $rv) = @_;
15 15
16 print "@$_\n" 16 print "@$_\n"
17 for @$rows; 17 for @$rows;
18 18
19 $cv->broadcast; 19 $cv->broadcast;
52use DBI (); 52use DBI ();
53 53
54use AnyEvent (); 54use AnyEvent ();
55use AnyEvent::Util (); 55use AnyEvent::Util ();
56 56
57our $VERSION = '1.0'; 57our $VERSION = '1.1';
58 58
59# this is the forked server code 59# this is the forked server code
60 60
61our $DBH; 61our $DBH;
62 62
71sub req_exec { 71sub req_exec {
72 my (undef, $st, @args) = @{+shift}; 72 my (undef, $st, @args) = @{+shift};
73 73
74 my $sth = $DBH->prepare_cached ($st, undef, 1); 74 my $sth = $DBH->prepare_cached ($st, undef, 1);
75 75
76 $sth->execute (@args) 76 my $rv = $sth->execute (@args)
77 or die $sth->errstr; 77 or die $sth->errstr;
78 78
79 [$sth->fetchall_arrayref] 79 [1, $sth->{NUM_OF_FIELDS} ? $sth->fetchall_arrayref : undef, { rv => $rv }]
80} 80}
81 81
82sub serve { 82sub serve {
83 my ($fh) = @_; 83 my ($fh) = @_;
84 84
111 } 111 }
112 } 112 }
113 } 113 }
114 }; 114 };
115 115
116 if (AnyEvent::WIN32) {
116 kill 9, $$; # no other way on the broken windows platform 117 kill 9, $$; # no other way on the broken windows platform
118 # and the above doesn't even work on windows, it seems the only
119 # way to is to leak memory and kill 9 from the parent. yay.
120 }
121
122 require POSIX;
123 POSIX::_exit (0);
124 # and the above kills the parent process on windows
117} 125}
118 126
119=head2 METHODS 127=head2 METHODS
120 128
121=over 4 129=over 4
265 $self->{ww} = AnyEvent->io (fh => $self->{fh}, poll => "w", cb => $self->{ww_cb}) 273 $self->{ww} = AnyEvent->io (fh => $self->{fh}, poll => "w", cb => $self->{ww_cb})
266 if length $self->{wbuf}; 274 if length $self->{wbuf};
267 } 275 }
268} 276}
269 277
270=item $dbh->exec ("statement", @args, $cb->($rows, %extra)) 278=item $dbh->exec ("statement", @args, $cb->($rows, $rv, ...))
271 279
272Executes the given SQL statement with placeholders replaced by 280Executes the given SQL statement with placeholders replaced by
273C<@args>. The statement will be prepared and cached on the server side, so 281C<@args>. The statement will be prepared and cached on the server side, so
274using placeholders is compulsory. 282using placeholders is compulsory.
275 283
276The callback will be called with the result of C<fetchall_arrayref> as 284The callback will be called with the result of C<fetchall_arrayref> as
277first argument and possibly a hash reference with additional information. 285first argument (or C<undef> if the statement wasn't a select statement)
286and the return value of C<execute> as second argument. Additional
287arguments might get passed as well.
278 288
279If an error occurs and the C<on_error> callback returns, then no arguments 289If an error occurs and the C<on_error> callback returns, then no arguments
280will be passed and C<$@> contains the error message. 290will be passed and C<$@> contains the error message.
281 291
282=cut 292=cut

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines