pyodbc 使用 DB2 从存储过程返回多个游标
我有一个 python 程序,它从 db2 数据库调用存储过程。我正在使用 results = curve.fetchall()
来处理存储过程的结果。但是,我的存储过程返回两个游标。 results
仅包含第一个。我需要一种方法来循环遍历尽可能多的光标。我希望 fetchmany() 是我的答案,但事实并非如此。
我需要能够执行多个结果集,因为我正在编写的程序只能调用一个存储过程。要回去并使其能够呼叫两个需要花费很多时间。除了这些事情之一之外,我还需要让 10 个游标返回。一切都是动态的,所以应用程序不知道它正在运行什么程序,它只是获取数据并将其吐入excel而不知道其含义。我需要一个游标用于数据,另一个游标用于不同类型的计数和总计。
我正在寻找一个内置函数来执行此操作,或者甚至可能是一个不同的库,因为我已经完成了谷歌搜索,看起来 pyodbc 并没有为 DB2 执行此操作。 DB2 是一个要求。
I have a python program that calls a stored procedure from db2 database. I am using results = cursor.fetchall()
to process the results of my stored procedure. However, my stored procedure returns two cursors. results
only contains the first one. I need a way to loop through as many cursors as I want. I was hoping fetchmany()
would be my answer but it is not.
I need to be able to do multiple result sets as the program I am writing can only call one stored procedure. It would take a lot to go back and make it to be able to call two. Besides with one of these things I need to make 10 cursors return. Everything is dynamic, so the application doesn't know what procedure it is running, it just gets the data and spits it into excel not knowing the meaning. I need one cursor for the data, and the other cursors for different types of counts and totals.
I am looking for a built in function to do this, or maybe even a different library because I have done my share of googling and it looks like pyodbc does not do this for DB2. DB2 is a requirement.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用光标的
nextset()
方法:https:// github.com/mkleehammer/pyodbc/wiki/Cursor#nextset示例代码:
如果有其他结果集可用,
nextset()
将返回True
,并且后续光标fetch 方法将从下一组返回行。如果没有其他可用集,该方法将返回None
。Use the
nextset()
method of the cursor: https://github.com/mkleehammer/pyodbc/wiki/Cursor#nextsetSample code:
nextset()
will returnTrue
if additional result sets are available, and subsequent cursor fetch methods will return rows from the next set. The method returnsNone
if no additional sets are available.只是为了记录而做一个小小的简化:
Just a small simplification for the record: