Revision 1 as of 2004-10-06 09:04:30

Clear message

What sucks about the DbApi

It totally misuses the cursor concept.

A cursor is a set of database rows you iterate over. It can be clientside or server-side.

In the DbApi, you first create a cursor object, then execute a statement on it, then fetch the results.

The normal way of using cursors with the DB-API is to reuse the cursor objects and fire new statements with them, and fetch new results.

This is totally misguided in my opinion.

A much better API should look similar to:

cx = dbapimodule.connect() cx.execute("insert into tablename(val) values (?)", ('foo',))

for row in cx.executeReader("select val from tablename"):

row = cx.executeRow("select max(val) from tablename")

etc.

executing statements logically belongs in the connection object, not in the cursor object.

Enough ranting for now, more will come some day. Maybe somebody can clean this up and add a few thoughts :)

Unable to edit the page? See the FrontPage for instructions.