Re: PG error handling

"Greg Sabino Mullane" <greg-738XdyZ4GzZWk0Htik3J/[email protected]>
Newsgroups gmane.comp.db.postgresql.dbdpg
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160


> Is there a way to distinguish the error I get from various methods (eg.
> connect) besides parsing the text? I try few connect errors (wrong user,
> wrong port) and the error code returned is 1 (DBI::err) and state is
> 25P01 (DBI::state) and the error string is vary.

The connect() method is much different from the other methods: once you 
are actually connected, you can get better error codes from the server 
itself. For the connect method, however, you'll need to parse the errstr 
yourself. Luckily, there is a fairly finite number of common connection 
errors.

Once connected, you can rely upon the $dbh->state() method to return 
something reasonable. Be aware, however, that these codes were developed 
by committee and are not usually very specific or useful. The list is here:

http://developer.postgresql.org/pgdocs/postgres/errcodes-appendix.html

Note that only a handful of those will appear in 99% of all errors.

- --
Greg Sabino Mullane greg-738XdyZ4GzZWk0Htik3J/[email protected]
End Point Corporation
PGP Key: 0x14964AC8 200708191130
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iD8DBQFGyGIrvJuQZxSWSsgRAyOVAJoD3U4w4kDT1Kql1ZuksmqtqgG50QCg1kk2
rzRDO77d9Xm+3iHDbhdlQrI=
=01ee
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.