[DB-SIG] [ANNOUNCEMENT] MySQLdb-0.1.3 released

M.-A. Lemburg mal@lemburg.com
Thu, 09 Mar 2000 22:42:55 +0100


Andy Dustman wrote:
> 
> On Thu, 9 Mar 2000, M.-A. Lemburg wrote:
> 
> > Andy Dustman wrote:
> > >
> > > cursor.fetchrow(), of course, returns the result as a sequence of values,
> > > usually a tuple. cursor.fetchrowDict() returns the result as a dictionary,
> > > where the keys are the column names and the values are the column values.
> >
> > How does this help with columns which are the result of
> > a SQL function, e.g. select max(value) from table ?
> 
> You'd probably want to use AS to rename computed columns, e.g.,
> 
> SELECT MAX(value) AS max_value FROM table;

Hmm, you're just moving complexity from Python into SQL, but...
anyways it's probably convenient to have :-)
 
> > Wouldn't the same functionality be available by simply
> > merging the information from cursor.description and the
> > result of .fetchone() (that's how my own abstract DB class works,
> > BTW) ?
> 
> Yep, and that's essentially what fetchoneDict() is doing. fetchoneDict()
> could have been implemented in Python to do that, but in this case, it's
> done in C: conn.fetch_row_as_dict(), conn.fetch_rows_as_dict(n),
> conn.fetch_all_rows_as_dict()); where conn is a _mysql.MYSQL connection
> object. result.describe() produces the DB API description tuple from some
> MySQL structures; where result is a _mySQL.MYSQL_RES result object. The
> various fetch_XXX_as_dict() methods just get this information directly out
> of some C data structures.
> 
> And, one of the things about MySQLdb is, since the top-level interface IS
> written in Python, you can directly subclass the Connection and Cursor
> objects (rather than writing wrappers), so really someone could have just
> added this on as their own subclass. Let's just say it's there due to
> popular demand, and documentated as non-portable.

Well, your Cursor and Connection object *are* already wrappers
around the C layer... ;-) I usually do the same for my ODBC
stuff: there are high level wrappers around the connection,
the tables, result set and rows -- all done in Python to make
reuse as easy as possible.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/