[mod_python] Passing Cursor Objects

David Fraser davidf at sjsoft.com
Fri Jul 18 09:58:00 EST 2003


Mike Looijmans wrote:

>Good explanation, I'm sure you're erring on the 'too much' side here.
>
>Anyway, MySQL has a quite nice LIMIT command for this purpose. You can not
>only get the 'first 10' rows, but you can also make it fetch the last 10 or
>from 30-40. So all you need is to keep track of where you were and what the
>query was (you could make the page into a form and add <input type=hidden>
>tags and prev/next submit buttons. Or you could put the query into the url.
>
>If you have really long queries (URLs are limited to 6kB) consider using
>either POST requests or store the query into the database and supply a
>'handle' (row ID) instead. Throw away the query after an hour or so...
>  
>
>>So the long and short of it is you'll have to open a new cursor for
>>each request from the web.  It may help to think about the state of the
>>cursor that's most important to you: not the connection ID to the MySQL
>>server or anything like that.  It's probably the row number the user
>>last viewed, along with the components of the query.  If you put *that*
>>information into the generated HTML in such a way that the browser will
>>send it back to you (again, <input> tags are good for this), then
>>you'll be able to create a cursor in the necessary state by grabbing
>>any old cursor and executing the appropriate query.
>>
>>I hope this helps.  I try to err on the side of too much explaination.
>>    
>>
Or if you did really, even after those explanations, want to store the 
cursor, you could create a unique key for it, save it in a global 
dictionary (but note problems with different threads/processes), get the 
client to remember the key (cookie/hidden field/URL) and retrieve the 
cursor using the key on the next request...
But you probably really don't need to do that.

David




More information about the Mod_python mailing list