[Tutor] tutorial for dbapi 2.0 how to use data (fwd)
Larry Blair
lbblair at adaptisinc.com
Tue May 11 19:28:39 EDT 2004
I am doing the same kind of stuff currently. Here is what I am using for
oracle and using cx's modules. To see the data I put a print row after the
last line in the for. This creates a list. A dictionary is any harder to do.
cur.execute("select file_name,tablespace_name ,bytes from dba_data_files
where tablespace_name not in (select DISTINCT TABLESPACE_NAME from
dba_rollback_segs where owner <> 'SYS')")
for row in cur.fetchall():
item = [row[0],row[1],row[2],"DATAFILE"]
DatabaseFileAttributes.append(item)
-----Original Message-----
From: Danny Yoo [mailto:dyoo at hkn.eecs.berkeley.edu]
Sent: Tuesday, May 11, 2004 2:31 PM
To: Tutor
Cc: jfabinani at yolo.com
Subject: Re: [Tutor] tutorial for dbapi 2.0 how to use data (fwd)
[Forwarding to Tutor: please make sure to keep Tutor at python.org in CC; if
I'm busy, we still want you to be able to get responses from the group.]
---------- Forwarded message ----------
Date: Tue, 11 May 2004 13:36:38 -0700
From: John Fabiani <jfabiani at yolo.com>
To: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] tutorial for dbapi 2.0 how to use data
Danny Yoo wrote:
>On Tue, 11 May 2004, John Fabiani wrote:
>>mycur=con.cursor()
>>mycur.execute("select * from sosord")
>>mydata=mycur.fetchmany(10)
>>
>>The above works and returns data. But know I need to understand how to
>>view the data. Maybe there is a way to convert the returned list into a
>>dictionary. A dictionary would allow me to get information by key (the
>>field name). Anyway, is there some paper or tutorial I can read on how
>>to view the return data?
>>
>
>If you are using MySQLdb, then yes, there is a way of getting a customized
>cursor that returns dictionaries instead of tuples. For example:
>
>###
>
>
>>>>import MySQLdb.cursors
>>>>cursor = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
>>>>cursor.execute("select * from pub_term where is_obsolete='n'")
>>>>
>>>>
>57562L
>
>
>>>>cursor.fetchone()
>>>>
>>>>
>{'parentage': None, 'definition': 'A complex containing a heterodimer of a
>catalytic subunit and a regulatory (adaptor) subunit of any
>phosphoinositide 3-kinase (PI3K).', 'pub_object_id': 47030L,
[text cut]
This is a great first step! I'm using the Postgres pgPySQL module. How
can I tell if the module supports the cursors that MySQL supports?
description appears to return a tuple that contains tuples. The first
column returns the field name - any chance you know what the other
columns mean?
So how do I setup the dictionary as in
{"id": 123, "go_external_id": 456, "name":"john", "type": "dumb",
"date_entered": 01/01/04 ...........}
The bottom line is I want to be able to access and change the data.
Isn't there some tutorial or something I can read that explains how this
is suppose to work?
I'd like to do things like the following:
loop thru the data
make some test
change some of the data in the current row/ list
Save the data...
The above would be just normal database activities.....
Thanks
John
_______________________________________________
Tutor maillist - Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor
__________________________________
Confidentiality Notice: This e-mail message, including any attachments, is
for the sole use of the intended recipient(s) and may contain information
that is confidential privileged and/or exempt from disclosure under
applicable law. Any unauthorized review, use, disclosure or distribution is
prohibited. If you are not the intended recipient, please contact the
sender by reply e-mail and destroy all copies of the original message.
Thank you.
More information about the Tutor
mailing list