Django多个结果集

时间:2013-12-04 18:03:47

标签: python mysql django stored-procedures

我有一个存储过程,我在我的Django应用程序中使用cursor.execute调用。存储过程返回2个结果集,但我似乎无法通过Django访问第二个。访问多个结果集的正确方法是什么?

2 个答案:

答案 0 :(得分:5)

我最终做了这样的事情:

cursor = connections['prod'].cursor()
cursor.execute('''Your SQL''')
row = cursor.fetchone()

# do what you need to do with the first result set

cursor.nextset() #sets cursor to the next result set

# fetchone or fetchall and do whatever you want with the next result set

答案 1 :(得分:0)

这将从存储过程中获取第二个结果集:

resultset2 = cursor.nextset().. #this returns 1 if it has result set 2 else -1..based on this call you can go for fetch
resultset2 = cursor.fetchall()