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

Chris Cogdon chris at cogdon.org
Sat Nov 20 16:56:04 CET 2004


On Nov 20, 2004, at 02:36, Peter Mott wrote:

> 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()

And... if you really need to ensure that they're done in separate SQL 
queries - for example, if you cannot hold onto the cursor between 
fetching each row - you can use MySQL's LIMIT or LIMIT/OFFSET syntax.

.... LIMIT 5, 1  will return a result set with a single entry, but 
offset 5 positions into the otherwise full result set.

The more-standard syntax of .... LIMIT 1 OFFSET 5 is supported by MySQL 
and other databases, such as PostgreSQL.

( LIMIT/OFFSET is supported by earlier versions of MySQL, but is far 
less standard than LIMIT/OFFSET)


-- 
    ("`-/")_.-'"``-._        Chris Cogdon <chris at cogdon.org>
     . . `; -._    )-;-,_`)
    (v_,)'  _  )`-.\  ``-'
   _.- _..-_/ / ((.'
((,.-'   ((,/   fL



More information about the DB-SIG mailing list