AnyEvent::DBI and postgresql

Andrey Khlopenov khlopenov.andrey at gmail.com
Fri May 9 19:11:19 CEST 2014


Hi.
I'm using code for connect to DB:

sub init {
  my %opts  = (@_);
  my $dbh   = delete $opts{'dbh'};

  my ($user, $password, $dsn) = ($1, $2, $3) if ($opts{'c'} =~
/^([^:]+):(.+)\@(DBI:.+)$/);

  undef $$dbh;
  $$dbh = new AnyEvent::DBI
    $dsn        //  $opts{'c'},
    $user       //  "",
    $password   //  "",
    timeout     =>  $opts{'timeout'},
    PrintError  =>  0,
    AutoCommit  =>  1,
    on_error    =>  sub {
      my $fatal = pop;

      chomp $@;
      print STDERR '[', AE::time, '|', ($dsn // $opts{'c'}), ']: ', $@,
"\n";
      $fatal and init(dbh => $dbh, c => $opts{'c'}, timeout =>
$opts{'timeout'});
    }
  ;
}

When function get $fatal in on_error, it's reconnecting to DB. It's working
with SQLite.
But when I try it with PostgreSQL, it's not working.
Had in STDERR "no connection to the server"(when shuting down PostgreSQL),
but $fatal is undef.
What is problem with it?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/anyevent/attachments/20140509/0f1fb9bc/attachment.html>


More information about the anyevent mailing list