[Tutor] Understanding cursors or MySQLdb problem
andy surany
mongo57a@comcast.net
Tue Feb 11 13:08:06 2003
Hello List!
I am using MySQLdb to access MySQL from my python program. I have a
class that does the following:
query='select ax, bx, cx from tablename'
a=self.cursor.execute(query)
b=self.cursor.fetchall()
(next part in a loop...)
name=self.cursor.description[i,0]
type=self.cursor.description[i,1]
print name, type
(end of loop)
This has been working fine. I return the data back to the calling
program, as such:
dbinfo=sql.Query()
and access it like:
data_element1.append(dbinfo.ax[i])
data_element2.append(dbinfo.bx[i])
etc................
This all has worked great! until I changed my query to look like:
query='select ax, bx, SUM(cx) from tablename'
Now, when I try data_element3.append(dbinfo.SUM(cx[i])) I get the
following error:
SQL instance has no attribute 'SUM'
When I look at 'print name, type', I see:
name ax, bx, SUM(cx)
type 254, 254, 5
I do note that the SUM introduces a new "type" (which I have no idea
what it is.....).
So............., do I have a problem understanding cursors? or is this a
unique MySQLdb issue, or ?????
I know this is kind of lengthy... but any help would be appreciated.
Regards,
Andy