-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160
> I would like to add error handing which looks at why DBI->connect()
> call using DBD::Pg fails and handle it appropriately. For example, if
> the authentication fails, I would like to handle that one way, and the
> db specified is not found, I would like to handle that a different
> way.
Best you can do is look at the error string. You can't rely on $DBI::state,
alas, as the SQL spec doesn't specify SQLSTATE codes at that level of
granularity. But as long as you keep your language settings constant,
you should be able to parse the strings returned. Something like this:
my $DSN = 'DBI:Pg:dbname=greg;port=5432';
my $dbh = DBI->connect($DSN, 'greg', '',
{AutoCommit=>0,RaiseError=>0,PrintError=>0});
## RaiseError=>0 is dangerous unless we check right away
if ($DBI::err) {
print "Got errstr as $DBI::errstr\n";
print "Got state as $DBI::state\n";
if ($DBI::errstr =~ /database "(.+)" does not exist/) {
&handle_no_database($1);
}
elsif ($DBI::errstr =~ /role "(.+)" does not exist/) {
&handle_bad_user($1);
}
else {
die "Connection failed: $DBI::errstr\n";
}
}
$dbh->{RaiseError} = 1;
print "Connected!\n";
- --
Greg Sabino Mullane [email protected]
End Point Corporation
PGP Key: 0x14964AC8 200906090835
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----
iEYEAREDAAYFAkouVywACgkQvJuQZxSWSshEtQCg7pyFP8S+qnpVXEsaxiDrq5d0
YoAAoLoW2xXenMqr81fSOH7E/fgVvaTV
=Pe4A
-----END PGP SIGNATURE-----