[python-sybase] How to deal with DatabaseError

Greg Ward gward-pysybase at python.net
Thu Jul 20 01:50:44 EST 2006


On 20 July 2006, Andrew McNamara said:
> >Am I the only one who thinks that there's an ugly flaw in the Python
> >Database API [...]
> 
> Only one? 8-)

No comment.  (This is the ugly flaw that's annoying me today.)

> I've seen people use things like:
> 
>     if ...:
>         from pyPgSQL import PgSQL as dbapi2
>     elif ...:
>         import psycopg2 as dbapi2
>     elif ...:
>         import sybase as dbapi2

What, in every script or module that does database interaction?  No thanks.
And what about the mythical script that migrates data from Sybase to
Postgres using both drivers?

BTW, PEP 249 (DB-API 2.0) has this under "Optional DB API Extensions":

    Connection Attributes .Error, .ProgrammingError, etc.

        All exception classes defined by the DB API standard should be
        exposed on the Connection objects as attributes (in addition
        to being available at module scope).

        These attributes simplify error handling in multi-connection
        environments.

        Warning Message: "DB-API extension connection.<exception> used"

Obviously this is no good unless all drivers that you want to use support
it.  I'll go see if I can whip up a patch for python-sybase.  In the worst
case, I could monkey-patch those attributes in to every Connection in my
abstraction layer.  (Blech.)

        Greg


More information about the Python-sybase mailing list