--- AnyEvent-DBI/DBI.pm 2008/06/06 15:35:46 1.1 +++ AnyEvent-DBI/DBI.pm 2008/06/06 15:44:34 1.2 @@ -47,6 +47,17 @@ [1] } +sub req_exec { + my (undef, $st, @args) = @{+shift}; + + my $sth = $DBH->prepare_cached ($st, undef, 1); + + $sth->execute (@args) + or die $sth->errstr; + + [$sth->fetchall_arrayref] +} + sub serve { my ($fh) = @_; @@ -81,8 +92,6 @@ } }; - warn $@;#d# - kill 9, $$; # no other way on the broken windows platform } @@ -119,7 +128,7 @@ then AnyEvent::DBI die's, otherwise it calls the original request callback without any arguments. -If omitted, then C will be called on any fatal errors, others will be ignored. +If omitted, then C will be called on any errors, fatal or not. =back @@ -166,7 +175,7 @@ } else { my $cb = shift @$req; $wself->_error ($res->[1], @$req); - $cb->[0](); + $cb->(); } } @@ -210,12 +219,10 @@ $self->{on_error}($self, $filename, $line, $fatal) if $self->{on_error}; - die "$error at $filename, line $line\n" - if $fatal; + die "$error at $filename, line $line\n"; } sub _req { - warn "\n";#d# my ($self, $cb, $filename, $line, $fatal) = splice @_, 0, 5, (); push @{ $self->{queue} }, [$cb, $filename, $line, $fatal]; @@ -236,17 +243,20 @@ =item $dbh->exec ("statement", @args, $cb->($rows, %extra)) Executes the given SQL statement with placeholders replaced by -C<@args>. The statement will be prepared and cached on the -server side, so using placeholders is compulsory. +C<@args>. The statement will be prepared and cached on the server side, so +using placeholders is compulsory. The callback will be called with the result of C as first argument and possibly a hash reference with additional information. +If an error occurs and the C callback returns, then no arguments +will be passed and C<$@> contains the error message. + =cut sub exec { my $cb = pop; - splice @_, 1, 0, $cb, (caller)[1,2], 0, "exec"; + splice @_, 1, 0, $cb, (caller)[1,2], 0, "req_exec"; goto &_req; }