From: Andrew M. <an...@ob...> - 2006-07-20 16:18:53
|
>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? Well, if you have a large system composed of many modules, it doesn't seem like much of an additional impost to put the "import...as" stuff in a module (I've found that I invariably end up with a module that wraps the dbapi to some degree other anyway). If you're mixing adapters, sure, it's somewhat more painful. I guess you could use something like: try: ... logic .. except (sybase.DatabaseError, PgSQL.DatabaseError), e: ... error logic... If you have a common module, you can put that tuple in it, eg: DatabaseError = sybase.DatabaseError, PgSQL.DatabaseError and then just catch with the tuple: try: ... logic .. except DatabaseError, e: ... error logic... > 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). [...] >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.) I must admit, I've never noticed that in the DBAPI spec, and a quick survey suggests support for it is the exception rather than the rule. It also doesn't help your second case above. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ |