[DB-SIG] How can I retrieve single records in a specific order?

Peter Mott peter at monicol.co.uk
Sat Nov 20 11:36:44 CET 2004

Hi Casey,

You need to check out the Python DB-API specification at
http://www.python.org/peps/pep-0249.html . Thge fetchone operation should
return the next record and then None when there no more. Something like:

RecordData = DatabaseCursor.fetchone()
while RecordData != None:
	do something
	RecordData = DatabaseCursor.fetchone()



> -----Original Message-----
> From: db-sig-bounces at python.org [mailto:db-sig-bounces at python.org] On
> Behalf Of Casey Bralla
> Sent: 19 November 2004 22:46
> To: db-sig at python.org
> Subject: [DB-SIG] How can I retrieve single records in a specific order?
> I'm writing a python application which will retrieve thousands of records
> from
> a MySQL database.  I'm having trouble getting sequential records in the
> order
> I want, and was hoping someone could offer suggestions of how to proceed.
> Here is the python code I've gotten so far....
> Database=MySQLdb.connect(db = Database, user = DatabaseUser, passwd =
> DatabasePassword, host = localhost)
> DatabaseCursor = Database.cursor()
> DatabaseCursor.execute("SELECT * FROM table1 ORDER BY field1")
> RecordData = DatabaseCursor.fetchone()
> You MySQL gurus can probably spot that I will receive a single record into
> "RecordData", and every time I run the routine, I will get the exact same
> record (in this case, the first record in the database table1 that is
> sorted
> by field1.)
> My Question:  But how can I get a single record in this sort order, and
> then
> retrieve the next record in this same sort order?
> TIA!
> --
> Casey Bralla
> Chief Nerd in Residence
> The NerdWorld Organisation
> _______________________________________________
> DB-SIG maillist  -  DB-SIG at python.org
> http://mail.python.org/mailman/listinfo/db-sig

More information about the DB-SIG mailing list