[DB-SIG] perl-DBI like module for Python?

Mihai Ibanescu misa at redhat.com
Wed May 26 09:49:38 EDT 2004

On Wed, May 26, 2004 at 01:02:45PM +0100, Stuart Bishop wrote:
> Hash: SHA1
> On 24/05/2004, at 4:57 PM, Mihai Ibanescu wrote:
> >Hello,
> >
> >I am not sure if it was mentioned before on this list.
> >Is there a module that does what the perl DBI module does?
> >What I mean by that is: a top-level module that exposes the API 
> >defined in the
> >DB API document, but with the ability to change backend drivers on the 
> >fly.
> No.
> The drivers have enough functionality that this extra layer is
> generally not needed. The major desire for such a library
> would be to standardize the parameter style used.

I tend to disagree.  If I want to write an application that populates a
Microsoft SQL database with data from an Oracle server (i.e. maintaining
connections to different kinds of databases at the same time), then I would
like to be able to catch exceptions in a sane way, without jumping through
hoops of 'this is a Microsoft DatabaseError while this is an Oracle
DatabaseError').  One could always use an intermediate step (dump the data in
a shelve or something like that), but I hope you see my point.

> >Example: I have my application running against Postgres. I have to be 
> >able to
> >port it to Oracle too. Unfortunately, code that tries to catch
> >DatabaseException will have to look for the cx_Oracle 
> >DatabaseException, not
> >for the postgres one.
> The exceptions are most likely exposed through your connection object
> (I think most the major drivers support this option now?).
> try:
> 	cur = con.cursor()
> 	cur.excecute('select foo from bar')
> except con.DatabaseException:
> 	print 'Oops!'

That is not the case in cx_Oracle or DCOracle2. It should be part of the DB API
if you want to rely on this.


More information about the DB-SIG mailing list