[DB-SIG] reg cursor.fetchall()

Andy Todd andy47 at halfcooked.com
Wed Feb 8 11:44:20 CET 2006


python eager wrote:
> Hi , This is my statment which will work fine. but the statment line is 
> long. How to split up these lines .
>  
> *Code Snippet :*
>  
> for PID,FIRSTNAME,MIDDLENAME,LASTNAME,
> MARITALSTATUS,EMPLOYEESTATUS,NOD,SALARY,
> POI,RADDRESS,OADDRESS,MNO,LNO,DOBD,DOBM,
> DOBY,DOID,DOIM,DOIY,DOED,DOEM,DOEY in cursor.fetchall():
>  
> Please help me
>  
> regards
> Python Eager
>  
> 
> _______________________________________________
> DB-SIG maillist  -  DB-SIG at python.org
> http://mail.python.org/mailman/listinfo/db-sig

The usual pattern is something like (untested, please ignore syntax errors);

 >>> myCursor.execute("SELECT x,y,z FROM tablea")
 >>> for row in cursor.fetchall():
...     print "Column x:", row[0]
...     print "y * z = %d" % (row[1] * row[2])

e.g. return each row of your results into a tuple and then reference the 
individual elements by index.

Sadly cx_Oracle doesn't offer different cursor classes like, for 
instance, MySQLdb;

http://dustman.net/andy/python/MySQLdb_obsolete/doc/MySQLdb-4.html#usage

So you can't refer to cursor results as dictionaries or other sequence 
types.

Regards,
Andy
-- 
--------------------------------------------------------------------------------
 From the desk of Andrew J Todd esq - http://www.halfcooked.com/


More information about the DB-SIG mailing list