[Zope] approach for assigning ODBC results to fieldnames as variables?

Bill Seitz fluxent@yahoo.com
Mon, 26 Feb 2001 14:23:22 -0800 (PST)


When you execute a SQL (select) query via ODBC and do
a fetchall(), you get back a result set as a tuple
(array). You can also ask for the cursor's
description, which returns a separate tuple, the first
column of which contains the fieldnames (or other
labels calculated by SQL).

Getting back an unlabelled tuple means that when you
want to write out a table of results (with some
individual handling of various fields, not just dumbly
iterating over the columns), you end up with an ugly
line like:
  Response.Write('<tr><td>%s<td>%s<td>%s<td><a
href="matterEdit.asp?clientID=%s&matterID=%s">%s</a><td>%s<td>%s</tr>'
%
(row[0],row[1],row[2],row[1],row[3],row[3],row[4],row[5]))

(this is a Python-via-IIS model, but would be similar
under Apache, etc.).

Is there a standard approach to assigning field names
to columns, so that this output line could be changed
to something like
  Response.Write('<tr><td>%s<td>%s<td>%s<td><a
href="matterEdit.asp?clientID=%s&matterID=%s">%s</a><td>%s<td>%s</tr>'
% (maxDate, clientID, clientName, clientID, jobID,
jobID, jobName, totalHours))
or even at least something like
  Response.Write('<tr><td>%s<td>%s<td>%s<td><a
href="matterEdit.asp?clientID=%s&matterID=%s">%s</a><td>%s<td>%s</tr>'
% (maxDate[i], clientID[i], clientName[i],
clientID[i], jobID[i], jobID[i], jobName[i],
totalHours[i]))

thx for your help...

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/