Thursday, December 30, 2010

Getting model instances from cursor fetches

Hello,

I have a stored procedure which creates a cursor for a query, and also returns the total count for the (unlimited) query. The query itself can be mapped to my model if ran through the raw method of the manager. However, I'm interested in using the procedure, rather than 2 separate queries for the count and the instances.

The documentation indicates that I should use the connection.cursor method for invoking custom sql. My initial plan is to first execute the procedure, which would return the count and open the query cursor, and then execute a 'fetch all' for that cursor (I doubt 'fetch next' would be better, since the result is stuffed into the django cursor anyway, but I could be wrong here). But after I fetch from the query cursor, how do I initialize my model objects with the data from that cursor?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment