Gadfly accessing results
aaron_watters at my-deja.com
aaron_watters at my-deja.com
Wed Jul 14 09:03:13 EDT 1999
In article <7mh2ed$hrb at newsops.execpc.com>,
Sim & Golda Zacks <simngolda at voyager.net> wrote:
> When I do a Select query in Gadfly how would I then be able to use
> individual fields from the results? In Delphi (my primary programming
> language) I would use a query and then call
> query.fieldbyname('fielname').value and I have access to all the
fields
> that were selected. How would I do this in Gadfly? For example my
select
> is for 5 fields and it returns 2 records. I want to be able to get
each
> field individually from each record
For gadfly, like other dbapi conformant python-database interfaces
you execute a query via a cursor
curs = connection.cursor()
...
curs.execute("select col1, col2, col3 from table")
Get the results of the select as a list of tuples via
resultlist = cursor.fetchall() # and similar
Get the 1st result row via
first = resultlist[0]
the third via
third = resultlist[2]
to get the 2nd column data value of the third row:
col_3_2 = third[1]
to loop through all the data values by row and then by column:
for row in resultlist:
for col in row:
print col,
print
Please see the gadfly documentation (with the package)
and the dbapi specification available in the db-sig area
of http://www.python.org.
-- Aaron Watters http://www.chordate.com
===
Do you expect me to talk?
No, Mr. Bond, I expect you to die.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
More information about the Python-list
mailing list