【问题标题】:Django Multiple Result SetsDjango 多个结果集
【发布时间】:2019-07-14 16:48:15
【问题描述】:

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

【问题讨论】:

  • 我没有亲自测试过,但从规格来看,您似乎想要cursor.nextset() 方法:python.org/dev/peps/pep-0249/#nextset
  • @PeterDeGlopper 很酷。看起来它会做到的。谢谢。我会玩它并发布解决方案的答案。

标签: python mysql django stored-procedures


【解决方案1】:

我最终做了这样的事情:

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2013-04-15
      • 2011-06-17
      • 2011-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多