Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to read multiple result sets using a ResultProxy object in sqlalchemy?

I'm trying to call a stored procedure that returns multiple result sets using SQLAlchemy. If it matters, underneath I'm using PyODBC and FreeTDS. I call the execute() method using a raw query with "exec" calling my stored procedure on a session object and get a ResultProxy object back.

With a raw pyodbc cursor, I can call the nextset() function to advance to the next result set. I see no way to do the same using the ResultProxy I get back from SQLAlchemy. Indeed, the docs say:

The DBAPI cursor will be closed by the ResultProxy when all of its result rows (if any) are exhausted.

Is there a way to read multiple result sets with SQLAlchemy, or will I have to perform this query with the raw DBAPI?

like image 572
Anton I. Sipos Avatar asked Apr 28 '12 00:04

Anton I. Sipos


1 Answers

support for nextset() is ticket 1635. It's two years old. It contains a partial patch which needs updating, in particular to work along with an execution option that passes along a hint that the statement will be returning multiple result sets, so that the resultproxy's existing autoclose behavior can remain the default. the feature would also need a lot of tests.

There's no major technical hurdle to this feature but there's generally very little interest in this use case. So at the moment you need to stick with the raw cursor, until people express enough interest in this feature to put momentum behind it again.

like image 106
zzzeek Avatar answered Sep 21 '22 23:09

zzzeek