Python Database Interfaces - Any Standard?

Thomas A. Bryan tbryan at python.net
Tue Dec 26 07:31:47 CET 2000


Brian Knox wrote:
> 
> The Perl DBI consists of two parts: the non database specific DBI module
> (DBI.pm). Then there is a DBD (DataBase Driver) module for each database.
> So, if I wanted to say work with Oracle, I'd use DBI.pm and the Oracle DBD.
> 
> use DBI;
> $dbh = DBI->connect( $dbi:Oracle:archaeo", "username", "password" );
> 
> To switch to say PostgreSQL, just change "Oracle" to "Pg" and make sure you
> have the DBD.

I haven't done much with Python and databases (yet), but I think that the 
idea is to be able to write 

import DCOracle
dbh = DCOracle.Connect( connect_string )
query = dbh.cursor()
query.execute( query_string )


To change to PostgreSQL, you'd have to change the import and the connection.

import pg
dbh = pg.connect( connect_string )
query = dbh.cursor()
query.execute( query_string )

Of course, this sort of change only works to the extent that you avoid 
any database-specific features of the database and the module that you're 
using.Some people achieve that goal, but it can be difficult in some 
applications to squeeze all of the performance you need without using some 
special feature that isn't portable.

---Tom



More information about the Python-list mailing list