Re: PATCH: pick exception type based on SQLSTATE

Karsten Hilbert <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
On Sat, Jan 12, 2008 at 12:29:26AM +0900, James Henstridge wrote:

> Currently the pq_raise() method will raise ProgrammingError unless it
> thinks that an IntegrityError is appropriate.
> 
> This patch extends the SQLSTATE checking to also pick from
> NotSupportedError, DataError, InternalError and OperationalError.  I
> used the following documents to help with the mapping:
> 
> http://www.postgresql.org/docs/current/static/errcodes-appendix.html
> http://pyodbc.sourceforge.net/docs.html#errors
> http://informixdb.svn.sourceforge.net/viewvc/informixdb/trunk/informixdb/ext/_informixdb.ec?view=markup#3402
> 
> If any of the mappings are wrong, it should be pretty easy to fix up.
> 
> The patch also changes pq_complete_error() to not force an exception
> type when calling pq_raise().  This means that e.g. integrity errors
> caught on transaction commit will raise IntegrityError instead of
> OperationalError (this required fixing one of the tests).
> 
> Does this look okay to commit?

Not that I have tested it but it *looks* good to me and
certainly *sounds* very sane and useful !

Thanks,
Karsten
-- 
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346
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.