[mod_python] new to list, will mod_python ever simulate what

Fabian Fagerholm fabbe at paniq.net
Mon Sep 9 12:00:11 EST 2002


On Mon, 2002-09-09 at 05:28, Mark Nielsen wrote:
> In Perl, the core DBI module takes care of all database connections which
> use DBI if you also use Apache DBI.
> I was thinking, there should be a standard way of doing it rather than
> relying on each database author.

Hence DBAPI.
http://www.python.org/topics/database/DatabaseAPI-2.0.html

> There should be a way to do it in Python irrelevant of which database
> connection you use. We would just need a way to make the database
> connections global variables which don't die. 

I agree that it would be useful to be able to keep any such objects
between browser requests. Perhaps there would be a way to place the
connection objects in the global namespace of each mod_python
subinterpreter so that they would continue to exist until the
subinterpreter dies?

But this is a separate issue from the "generic database access" issue.

> So, I guess, I probably will have to make up a way to do it. 
> I use MySQL, PostgreSQL, and Oracle, and also DBM, so I need one way
> for all database connections. 

Even the three SQL-capable ones have slight variations in the SQL syntax
which makes it hard to find a good lowest common denominator that could
be accepted as "standard".

I would write an abstract class that defines the behavior you need and
then four subclasses to implement that behavior for the four database
back-ends you mention. The interface to your application would be your
own, and the interface to each database would make use of DBAPI 2.0
modules specific to each database.

Making the abstract class "standard" makes little sense since it's
probably not very large or complicated, and it's often quite specific to
your application.

I also fail to see how Perl DBI solves certain issues. For example, if
you use Perl DBI and write an application that relies on transactional
capabilities of the database, and you move to a database without
transactional capabilities (MySQL with MyISAM tables, for instance) then
you'll have to adapt your code.
Also, in every single Perl DBI example I've seen, there's SQL embedded
in the code. I probably don't understand DBI but it seems to me that
this makes it essentially impossible to write code for, say, an Oracle
database that makes use of Oracle-specific features, and then run the
same code with a MySQL database as back-end. Or can DBI somehow emulate
the behavior of these databases?

So there really isn't any way out - the back-ends are just too
different. With good use of classes you can at least separate the
databases from the functional code in your particular application.

Cheers,
Fabian


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 240 bytes
Desc: This is a digitally signed message part
Url : http://mailman.modpython.org/pipermail/mod_python/attachments/20020909/f0263eda/attachment-0003.bin


More information about the Mod_python mailing list