[PYTHON DB-SIG] Re: Python Database API

Greg Stein greg_stein@eshop.com
Tue, 14 May 1996 18:50:57 -0800

At 11:26 AM 5/15/96, David Morley wrote:
>I was reading the Python Database API document and I couldn't figure out
>how this would apply to mSQL.  In particular, how do you send a query to
>the database and get back the rows?  It all seems far more complex than
>the ``old-interface mSQL'':
>db.query('select * from mytable')

Queries are run in two steps: execute() then a fetchXXX method. For example:

db = msqldb.msqldb('mydatabase')
db.execute('select * from mytable')
rows = db.fetchall()

The 'rows' would be a list of tuples containing the contents of the rows.

The introduction of the "cursor" concept is primarily for performance
purposes and would only be available for databases that use them. Since
mSQL doesn't have them, your don't have to worry about them at all -- the
"cursor methods" would be run directly on the database connection object.

The reason for splitting up the execute/fetch is simply that many SQL
statements don't return values (INSERT, UPDATE, DELETE, etc), so they would
only need an execute(). Also, you could do something like:

db.execute('select * from mytable')
print db.description

That would print out a description of the results before their actual
fetch. The split is also useful for enabling some types of performance

I hope this clears up how the interface might work. I started on a
compatibility module that works with the mSQL module, but presents the new
interface. It is a bit out of date, though. I have another module that
works for the Postgres95 database (using the PyGres module). One day, I
might write new C modules for better functionality, but they work well
enough now.

Feel free to ask away if you have more questions/comments!


Greg Stein, eShop Inc.

DB-SIG  - SIG on Tabular Databases in Python

send messages to: db-sig@python.org
administrivia to: db-sig-request@python.org